Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
<Project>

Check failure on line 1 in eng/Versions.props

View check run for this annotation

Azure Pipelines / efcore-ci (Build Linux)

eng/Versions.props#L1

eng/Versions.props(1,1): error MSB4067: (NETCORE_ENGINEERING_TELEMETRY=Restore) The element <#text> beneath element <Project> is unrecognized.

Check failure on line 1 in eng/Versions.props

View check run for this annotation

Azure Pipelines / efcore-ci (Build macOS)

eng/Versions.props#L1

eng/Versions.props(1,1): error MSB4067: (NETCORE_ENGINEERING_TELEMETRY=Restore) The element <#text> beneath element <Project> is unrecognized.

Check failure on line 1 in eng/Versions.props

View check run for this annotation

Azure Pipelines / efcore-ci

eng/Versions.props#L1

eng/Versions.props(1,1): error MSB4067: (NETCORE_ENGINEERING_TELEMETRY=Restore) The element <#text> beneath element <Project> is unrecognized.

Check failure on line 1 in eng/Versions.props

View check run for this annotation

Azure Pipelines / efcore-ci

eng/Versions.props#L1

eng/Versions.props(1,1): error MSB4067: (NETCORE_ENGINEERING_TELEMETRY=Restore) The element <#text> beneath element <Project> is unrecognized.
<Import Project="Version.Details.props" Condition="Exists('Version.Details.props')" />
<PropertyGroup Label="Version settings">
<VersionPrefix>10.0.1</VersionPrefix>
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
<PreReleaseVersionIteration></PreReleaseVersionIteration>
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
When StabilizePackageVersion is set to 'true', this branch will produce stable outputs for 'Shipping' packages
-->
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">true</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
<PreReleaseVersionLabel Condition="'$(StabilizePackageVersion)' != 'true'">preview</PreReleaseVersionLabel>
<PreReleaseVersionLabel Condition="'$(StabilizePackageVersion)' == 'true' and $(VersionPrefix.EndsWith('.0'))">rtm</PreReleaseVersionLabel>
<PreReleaseVersionLabel Condition="'$(StabilizePackageVersion)' == 'true' and !$(VersionPrefix.EndsWith('.0'))">servicing</PreReleaseVersionLabel>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<DefaultNetCoreTargetFramework>net10.0</DefaultNetCoreTargetFramework>
</PropertyGroup>
<PropertyGroup Label="Arcade settings">
<UsingToolXliff>False</UsingToolXliff>
</PropertyGroup>
<PropertyGroup Label="MSBuild and Roslyn" Condition="'$(IsServicingBuild)' == 'true'">
<!-- For MSBuild and Roslyn packages use the previous stable version until the current stable build is released. -->
<MicrosoftBuildFrameworkVersion>17.14.28</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildUtilitiesCoreVersion>17.14.28</MicrosoftBuildUtilitiesCoreVersion>
<MicrosoftBuildTasksCoreVersion>17.14.28</MicrosoftBuildTasksCoreVersion>
<MicrosoftCodeAnalysisCSharpVersion>4.14.0</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.14.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildVersion>4.14.0</MicrosoftCodeAnalysisWorkspacesMSBuildVersion>
</PropertyGroup>
<!-- Revert once roslyn publishes 5.0.0 packages
<PropertyGroup Label="MSBuild and Roslyn" Condition="'$(IsServicingBuild)' == 'true'">
<!-- Use the current stable builds for MSBuild and Roslyn packages, next version (non-servicing) will use the preview builds -->
<MicrosoftBuildFrameworkVersion>17.15.0</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildUtilitiesCoreVersion>17.15.0</MicrosoftBuildUtilitiesCoreVersion>
<MicrosoftBuildTasksCoreVersion>17.15.0</MicrosoftBuildTasksCoreVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Design/EFCore.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<ItemGroup>
<PackageReference Include="Humanizer.Core" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" PrivateAssets="analyzers;build" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
<PackageReference Include="Microsoft.Extensions.HostFactoryResolver.Sources" PrivateAssets="All" />
<PackageReference Include="Mono.TextTemplating" />
Expand Down
5 changes: 5 additions & 0 deletions src/EFCore.Tasks/Tasks/Internal/OperationTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public abstract class OperationTaskBase : ToolTask
/// </summary>
public bool Nullable { get; set; }

/// <summary>
/// Runtime copy local items for dependency resolution.
/// </summary>
public ITaskItem[]? RuntimeCopyLocalItems { get; set; }

/// <summary>
/// The additional arguments to pass to the dotnet-ef command.
/// </summary>
Expand Down
46 changes: 46 additions & 0 deletions src/EFCore.Tasks/Tasks/OptimizeDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public override bool Execute()
if (PrecompileQueries)
{
AdditionalArguments.Add("--precompile-queries");

CopyBuildHost();
}

AdditionalArguments.Add("--nativeaot");
Expand All @@ -106,4 +108,48 @@ public override bool Execute()

return !Log.HasLoggedErrors;
}

private void CopyBuildHost()
{
var msbuildWorkspacesItem = RuntimeCopyLocalItems?.FirstOrDefault(item =>
string.Equals(item.GetMetadata("Filename"), "Microsoft.CodeAnalysis.Workspaces.MSBuild", StringComparison.OrdinalIgnoreCase));
if (msbuildWorkspacesItem == null
|| !string.Equals(msbuildWorkspacesItem.GetMetadata("CopyLocal"), "true", StringComparison.OrdinalIgnoreCase)
|| msbuildWorkspacesItem.GetMetadata("FullPath") is not { } fullPath
|| string.IsNullOrEmpty(fullPath)
|| Path.GetDirectoryName(fullPath) is not { } itemDirectory
|| string.IsNullOrEmpty(itemDirectory))
{
return;
}

var contentFilesPath = Path.GetFullPath(Path.Combine(itemDirectory, "..", "..", "contentFiles", "any", "any"));
var targetDir = Path.GetDirectoryName(Path.GetFullPath(Assembly.ItemSpec))!;

CopyDirectoryRecursive(contentFilesPath, targetDir);
}

private static void CopyDirectoryRecursive(string sourceDir, string targetDir)
{
var directory = new DirectoryInfo(sourceDir);
if (!directory.Exists)
{
return;
}

Directory.CreateDirectory(targetDir);
foreach (var file in directory.GetFiles())
{
var filePath = Path.Combine(targetDir, file.Name);
if (!File.Exists(filePath))
{
file.CopyTo(filePath, overwrite: false);
}
}

foreach (var subDir in directory.GetDirectories())
{
CopyDirectoryRecursive(subDir.FullName, Path.Combine(targetDir, subDir.Name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ For Publish:
TargetNamespace="$(EFTargetNamespace)"
Language="$(Language)"
Nullable="$(EFNullable)"
RuntimeCopyLocalItems="@(RuntimeCopyLocalItems)"
OutputDir="$(EFOutputDir)"
Project="$(MSBuildProjectFullPath)"
ProjectDir="$(MSBuildProjectDirectory)"
Expand Down
18 changes: 18 additions & 0 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,24 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip
$params += '--design-assembly', $designReference.FullPath
}

$msbuildWorkspacesItem = $references.Items.RuntimeCopyLocalItems | ? {
$_.Filename -eq 'Microsoft.CodeAnalysis.Workspaces.MSBuild'
} | Select-Object -First 1

if ($msbuildWorkspacesItem -ne $null -and $msbuildWorkspacesItem.CopyLocal -eq 'true')
{
$itemDirectory = [IO.Path]::GetDirectoryName($msbuildWorkspacesItem.FullPath)
if ($itemDirectory)
{
$contentFilesPath = [IO.Path]::GetFullPath([IO.Path]::Combine($itemDirectory, '..', '..', 'contentFiles', 'any', 'any'))

if ([IO.Directory]::Exists($contentFilesPath))
{
Copy-Item "$contentFilesPath\*" $targetDir -Recurse -ErrorAction SilentlyContinue
}
}
}

$arguments = ToArguments $params
if ($applicationArgs)
{
Expand Down
51 changes: 50 additions & 1 deletion src/dotnet-ef/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ public static Project FromFile(

var metadata = JsonSerializer.Deserialize<ProjectMetadata>(output.ToString())!;

var designAssembly = metadata.Items["RuntimeCopyLocalItems"]
var runtimeCopyLocalItems = metadata.Items["RuntimeCopyLocalItems"];

var designAssembly = runtimeCopyLocalItems
.Select(i => i["FullPath"])
.FirstOrDefault(i => i.Contains("Microsoft.EntityFrameworkCore.Design", StringComparison.InvariantCulture));
var properties = metadata.Properties;

var outputPath = Path.GetFullPath(Path.Combine(properties[nameof(ProjectDir)]!, properties[nameof(OutputPath)]!));
CopyBuildHost(runtimeCopyLocalItems, outputPath);

var platformTarget = properties[nameof(PlatformTarget)];
if (platformTarget.Length == 0)
{
Expand Down Expand Up @@ -126,6 +131,50 @@ private record class ProjectMetadata
public Dictionary<string, Dictionary<string, string>[]> Items { get; set; } = null!;
}

private static void CopyBuildHost(
Dictionary<string, string>[] runtimeCopyLocalItems,
string targetDir)
{
var msbuildWorkspacesItem = runtimeCopyLocalItems.FirstOrDefault(item =>
string.Equals(item["Filename"], "Microsoft.CodeAnalysis.Workspaces.MSBuild", StringComparison.OrdinalIgnoreCase));

if (msbuildWorkspacesItem == null
|| !msbuildWorkspacesItem.TryGetValue("CopyLocal", out var copyLocal)
|| !string.Equals(copyLocal, "true", StringComparison.OrdinalIgnoreCase)
|| !msbuildWorkspacesItem.TryGetValue("FullPath", out var fullPath)
|| string.IsNullOrEmpty(fullPath))
{
return;
}

var contentFilesPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fullPath)!, "..", "..", "contentFiles", "any", "any"));
CopyDirectoryRecursive(contentFilesPath, targetDir);
}

private static void CopyDirectoryRecursive(string sourceDir, string targetDir)
{
var directory = new DirectoryInfo(sourceDir);
if (!directory.Exists)
{
return;
}

Directory.CreateDirectory(targetDir);
foreach (var file in directory.GetFiles())
{
var filePath = Path.Combine(targetDir, file.Name);
if (!File.Exists(filePath))
{
file.CopyTo(filePath, overwrite: false);
}
}

foreach (var subDir in directory.GetDirectories())
{
CopyDirectoryRecursive(subDir.FullName, Path.Combine(targetDir, subDir.Name));
}
}

public void Build(IEnumerable<string>? additionalArgs)
{
var args = new List<string> { "build" };
Expand Down
49 changes: 18 additions & 31 deletions src/ef/ReflectionOperationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Tools.Properties;

#if NET
using System.Runtime.Loader;
#endif
Expand Down Expand Up @@ -58,18 +59,13 @@ public ReflectionOperationExecutor(
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

#if NET
_commandsAssembly = AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
_commandsAssembly = DesignAssemblyPath != null
? AssemblyLoadContext.LoadFromAssemblyPath(DesignAssemblyPath)
: AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
#else
if (DesignAssemblyPath != null)
{
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath);
assemblyPath = Path.Combine(assemblyPath, DesignAssemblyName + ".dll");
_commandsAssembly = Assembly.LoadFrom(assemblyPath);
}
else
{
_commandsAssembly = Assembly.Load(DesignAssemblyName);
}
_commandsAssembly = DesignAssemblyPath != null
? Assembly.LoadFrom(DesignAssemblyPath)
: Assembly.Load(DesignAssemblyName);
#endif
var reportHandlerType = _commandsAssembly.GetType(ReportHandlerTypeName, throwOnError: true, ignoreCase: false)!;

Expand Down Expand Up @@ -109,16 +105,12 @@ protected AssemblyLoadContext AssemblyLoadContext
return _assemblyLoadContext;
}

if (DesignAssemblyPath != null)
AssemblyLoadContext.Default.Resolving += (context, name) =>
{
AssemblyLoadContext.Default.Resolving += (context, name) =>
{
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath)!;
assemblyPath = Path.Combine(assemblyPath, name.Name + ".dll");
return File.Exists(assemblyPath) ? context.LoadFromAssemblyPath(assemblyPath) : null;
};
_assemblyLoadContext = AssemblyLoadContext.Default;
}
var assemblyPath = Path.Combine(AppBasePath, name.Name + ".dll");
return File.Exists(assemblyPath) ? context.LoadFromAssemblyPath(assemblyPath) : null;
};
_assemblyLoadContext = AssemblyLoadContext.Default;

return AssemblyLoadContext.Default;
}
Expand All @@ -136,18 +128,13 @@ public override string? EFCoreVersion

Assembly? assembly = null;
#if NET
assembly = AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
assembly = DesignAssemblyPath != null
? AssemblyLoadContext.LoadFromAssemblyPath(DesignAssemblyPath)
: AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
#else
if (DesignAssemblyPath != null)
{
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath);
assemblyPath = Path.Combine(assemblyPath, DesignAssemblyName + ".dll");
assembly = Assembly.LoadFrom(assemblyPath);
}
else
{
assembly = Assembly.Load(DesignAssemblyName);
}
assembly = DesignAssemblyPath != null
? Assembly.LoadFrom(DesignAssemblyPath)
: Assembly.Load(DesignAssemblyName);
#endif
_efcoreVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
Expand Down
Loading