Skip to content

Commit 6faf008

Browse files
committed
Copy BuildHost manually instead of referencing contentFiles from Microsoft.CodeAnalysis.Workspaces.MSBuild
Fixes #36970
1 parent b1f65de commit 6faf008

File tree

11 files changed

+153
-75
lines changed

11 files changed

+153
-75
lines changed

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
<PackageVersion Include="NetTopologySuite.IO.SqlServerBytes" Version="2.1.0" />
5454
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
5555
<PackageVersion Include="mod_spatialite" Version="4.3.0.1" />
56-
<PackageVersion Include="SQLitePCLRaw.core" Version="$(SQLitePCLRawVersion)" />
57-
<PackageVersion Include="SQLitePCLRaw.bundle_sqlite3" Version="$(SQLitePCLRawVersion)" />
58-
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="$(SQLitePCLRawVersion)" />
56+
<PackageVersion Include="SQLitePCLRaw.core" Version="2.1.11" />
57+
<PackageVersion Include="SQLitePCLRaw.bundle_sqlite3" Version="2.1.11" />
58+
<PackageVersion Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.11" />
5959
</ItemGroup>
6060
</Project>

eng/Versions.props

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<Import Project="Version.Details.props" Condition="Exists('Version.Details.props')" />
33
<PropertyGroup Label="Version settings">
44
<VersionPrefix>10.0.1</VersionPrefix>
5-
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
5+
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
66
<PreReleaseVersionIteration></PreReleaseVersionIteration>
7-
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
7+
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
88
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
99
<!--
1010
When StabilizePackageVersion is set to 'true', this branch will produce stable outputs for 'Shipping' packages
@@ -17,29 +17,12 @@
1717
<UsingToolXliff>False</UsingToolXliff>
1818
</PropertyGroup>
1919
<PropertyGroup Label="MSBuild and Roslyn" Condition="'$(IsServicingBuild)' == 'true'">
20-
<!-- For MSBuild and Roslyn packages use the previous stable version until the current stable build is released. -->
21-
<MicrosoftBuildFrameworkVersion>17.14.28</MicrosoftBuildFrameworkVersion>
22-
<MicrosoftBuildUtilitiesCoreVersion>17.14.28</MicrosoftBuildUtilitiesCoreVersion>
23-
<MicrosoftBuildTasksCoreVersion>17.14.28</MicrosoftBuildTasksCoreVersion>
24-
<MicrosoftCodeAnalysisCSharpVersion>4.14.0</MicrosoftCodeAnalysisCSharpVersion>
25-
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.14.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
26-
<MicrosoftCodeAnalysisWorkspacesMSBuildVersion>4.14.0</MicrosoftCodeAnalysisWorkspacesMSBuildVersion>
27-
</PropertyGroup>
28-
<!-- Revert once roslyn publishes 5.0.0 packages
29-
<PropertyGroup Label="MSBuild and Roslyn" Condition="'$(IsServicingBuild)' == 'true'">
20+
<!-- Use the current stable builds for MSBuild and Roslyn packages, next version (non-servicing) will use the preview builds -->
3021
<MicrosoftBuildFrameworkVersion>17.15.0</MicrosoftBuildFrameworkVersion>
3122
<MicrosoftBuildUtilitiesCoreVersion>17.15.0</MicrosoftBuildUtilitiesCoreVersion>
3223
<MicrosoftBuildTasksCoreVersion>17.15.0</MicrosoftBuildTasksCoreVersion>
3324
<MicrosoftCodeAnalysisCSharpVersion>5.0.0</MicrosoftCodeAnalysisCSharpVersion>
3425
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>5.0.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
3526
<MicrosoftCodeAnalysisWorkspacesMSBuildVersion>5.0.0</MicrosoftCodeAnalysisWorkspacesMSBuildVersion>
36-
</PropertyGroup> -->
37-
<PropertyGroup Label="Other dependencies">
38-
<MicrosoftCodeAnalysisAnalyzerTestingVersion>1.1.3-beta1.24423.1</MicrosoftCodeAnalysisAnalyzerTestingVersion>
39-
<MicrosoftCodeAnalysisCSharpTestingVersion>1.1.3-beta1.24352.1</MicrosoftCodeAnalysisCSharpTestingVersion>
40-
<AzureIdentityVersion>1.14.2</AzureIdentityVersion>
41-
<AzureResourceManagerCosmosDBVersion>1.3.2</AzureResourceManagerCosmosDBVersion>
42-
<OpenTelemetryExporterInMemoryVersion>1.12.0</OpenTelemetryExporterInMemoryVersion>
43-
<SQLitePCLRawVersion>2.1.11</SQLitePCLRawVersion>
4427
</PropertyGroup>
4528
</Project>

src/EFCore.Design/EFCore.Design.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<ItemGroup>
5959
<PackageReference Include="Humanizer.Core" />
6060
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
61-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" PrivateAssets="analyzers;build" />
61+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
6262
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
6363
<PackageReference Include="Microsoft.Extensions.HostFactoryResolver.Sources" PrivateAssets="All" />
6464
<PackageReference Include="Mono.TextTemplating" />

src/EFCore.Tasks/Tasks/Internal/OperationTaskBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public abstract class OperationTaskBase : ToolTask
8181
/// </summary>
8282
public bool Nullable { get; set; }
8383

84+
/// <summary>
85+
/// Runtime copy local items for dependency resolution.
86+
/// </summary>
87+
public ITaskItem[]? RuntimeCopyLocalItems { get; set; }
88+
8489
/// <summary>
8590
/// The additional arguments to pass to the dotnet-ef command.
8691
/// </summary>

src/EFCore.Tasks/Tasks/OptimizeDbContext.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public override bool Execute()
8080
if (PrecompileQueries)
8181
{
8282
AdditionalArguments.Add("--precompile-queries");
83+
84+
CopyBuildHost();
8385
}
8486

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

107109
return !Log.HasLoggedErrors;
108110
}
111+
112+
private void CopyBuildHost()
113+
{
114+
var msbuildWorkspacesItem = RuntimeCopyLocalItems?.FirstOrDefault(item =>
115+
string.Equals(item.GetMetadata("Filename"), "Microsoft.CodeAnalysis.Workspaces.MSBuild", StringComparison.OrdinalIgnoreCase));
116+
if (msbuildWorkspacesItem == null
117+
|| !string.Equals(msbuildWorkspacesItem.GetMetadata("CopyLocal"), "true", StringComparison.OrdinalIgnoreCase)
118+
|| msbuildWorkspacesItem.GetMetadata("FullPath") is not { } fullPath
119+
|| string.IsNullOrEmpty(fullPath)
120+
|| Path.GetDirectoryName(fullPath) is not { } itemDirectory
121+
|| string.IsNullOrEmpty(itemDirectory))
122+
{
123+
return;
124+
}
125+
126+
var contentFilesPath = Path.GetFullPath(Path.Combine(itemDirectory, "..", "..", "contentFiles", "any", "any"));
127+
var targetDir = Path.GetDirectoryName(Path.GetFullPath(Assembly.ItemSpec))!;
128+
129+
CopyDirectoryRecursive(contentFilesPath, targetDir);
130+
}
131+
132+
private static void CopyDirectoryRecursive(string sourceDir, string targetDir)
133+
{
134+
var directory = new DirectoryInfo(sourceDir);
135+
if (!directory.Exists)
136+
{
137+
return;
138+
}
139+
140+
Directory.CreateDirectory(targetDir);
141+
foreach (var file in directory.GetFiles())
142+
{
143+
var filePath = Path.Combine(targetDir, file.Name);
144+
if (!File.Exists(filePath))
145+
{
146+
file.CopyTo(filePath, overwrite: false);
147+
}
148+
}
149+
150+
foreach (var subDir in directory.GetDirectories())
151+
{
152+
CopyDirectoryRecursive(subDir.FullName, Path.Combine(targetDir, subDir.Name));
153+
}
154+
}
109155
}

src/EFCore.Tasks/buildTransitive/Microsoft.EntityFrameworkCore.Tasks.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ For Publish:
106106
TargetNamespace="$(EFTargetNamespace)"
107107
Language="$(Language)"
108108
Nullable="$(EFNullable)"
109+
RuntimeCopyLocalItems="@(RuntimeCopyLocalItems)"
109110
OutputDir="$(EFOutputDir)"
110111
Project="$(MSBuildProjectFullPath)"
111112
ProjectDir="$(MSBuildProjectDirectory)"

src/EFCore.Tools/tools/EntityFrameworkCore.psm1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,24 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip
13381338
$params += '--design-assembly', $designReference.FullPath
13391339
}
13401340

1341+
$msbuildWorkspacesItem = $references.Items.RuntimeCopyLocalItems | ? {
1342+
$_.Filename -eq 'Microsoft.CodeAnalysis.Workspaces.MSBuild'
1343+
} | Select-Object -First 1
1344+
1345+
if ($msbuildWorkspacesItem -ne $null -and $msbuildWorkspacesItem.CopyLocal -eq 'true')
1346+
{
1347+
$itemDirectory = [IO.Path]::GetDirectoryName($msbuildWorkspacesItem.FullPath)
1348+
if ($itemDirectory)
1349+
{
1350+
$contentFilesPath = [IO.Path]::GetFullPath([IO.Path]::Combine($itemDirectory, '..', '..', 'contentFiles', 'any', 'any'))
1351+
1352+
if ([IO.Directory]::Exists($contentFilesPath))
1353+
{
1354+
Copy-Item "$contentFilesPath\*" $targetDir -Recurse -ErrorAction SilentlyContinue
1355+
}
1356+
}
1357+
}
1358+
13411359
$arguments = ToArguments $params
13421360
if ($applicationArgs)
13431361
{

src/dotnet-ef/Project.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ public static Project FromFile(
9090

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

93-
var designAssembly = metadata.Items["RuntimeCopyLocalItems"]
93+
var runtimeCopyLocalItems = metadata.Items["RuntimeCopyLocalItems"];
94+
95+
var designAssembly = runtimeCopyLocalItems
9496
.Select(i => i["FullPath"])
9597
.FirstOrDefault(i => i.Contains("Microsoft.EntityFrameworkCore.Design", StringComparison.InvariantCulture));
9698
var properties = metadata.Properties;
9799

100+
var outputPath = Path.GetFullPath(Path.Combine(properties[nameof(ProjectDir)]!, properties[nameof(OutputPath)]!));
101+
CopyBuildHost(runtimeCopyLocalItems, outputPath);
102+
98103
var platformTarget = properties[nameof(PlatformTarget)];
99104
if (platformTarget.Length == 0)
100105
{
@@ -126,6 +131,50 @@ private record class ProjectMetadata
126131
public Dictionary<string, Dictionary<string, string>[]> Items { get; set; } = null!;
127132
}
128133

134+
private static void CopyBuildHost(
135+
Dictionary<string, string>[] runtimeCopyLocalItems,
136+
string targetDir)
137+
{
138+
var msbuildWorkspacesItem = runtimeCopyLocalItems.FirstOrDefault(item =>
139+
string.Equals(item["Filename"], "Microsoft.CodeAnalysis.Workspaces.MSBuild", StringComparison.OrdinalIgnoreCase));
140+
141+
if (msbuildWorkspacesItem == null
142+
|| !msbuildWorkspacesItem.TryGetValue("CopyLocal", out var copyLocal)
143+
|| !string.Equals(copyLocal, "true", StringComparison.OrdinalIgnoreCase)
144+
|| !msbuildWorkspacesItem.TryGetValue("FullPath", out var fullPath)
145+
|| string.IsNullOrEmpty(fullPath))
146+
{
147+
return;
148+
}
149+
150+
var contentFilesPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fullPath)!, "..", "..", "contentFiles", "any", "any"));
151+
CopyDirectoryRecursive(contentFilesPath, targetDir);
152+
}
153+
154+
private static void CopyDirectoryRecursive(string sourceDir, string targetDir)
155+
{
156+
var directory = new DirectoryInfo(sourceDir);
157+
if (!directory.Exists)
158+
{
159+
return;
160+
}
161+
162+
Directory.CreateDirectory(targetDir);
163+
foreach (var file in directory.GetFiles())
164+
{
165+
var filePath = Path.Combine(targetDir, file.Name);
166+
if (!File.Exists(filePath))
167+
{
168+
file.CopyTo(filePath, overwrite: false);
169+
}
170+
}
171+
172+
foreach (var subDir in directory.GetDirectories())
173+
{
174+
CopyDirectoryRecursive(subDir.FullName, Path.Combine(targetDir, subDir.Name));
175+
}
176+
}
177+
129178
public void Build(IEnumerable<string>? additionalArgs)
130179
{
131180
var args = new List<string> { "build" };

src/ef/ReflectionOperationExecutor.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.EntityFrameworkCore.Design.Internal;
88
using Microsoft.EntityFrameworkCore.Infrastructure;
99
using Microsoft.EntityFrameworkCore.Tools.Properties;
10+
1011
#if NET
1112
using System.Runtime.Loader;
1213
#endif
@@ -58,18 +59,13 @@ public ReflectionOperationExecutor(
5859
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
5960

6061
#if NET
61-
_commandsAssembly = AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
62+
_commandsAssembly = DesignAssemblyPath != null
63+
? AssemblyLoadContext.LoadFromAssemblyPath(DesignAssemblyPath)
64+
: AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
6265
#else
63-
if (DesignAssemblyPath != null)
64-
{
65-
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath);
66-
assemblyPath = Path.Combine(assemblyPath, DesignAssemblyName + ".dll");
67-
_commandsAssembly = Assembly.LoadFrom(assemblyPath);
68-
}
69-
else
70-
{
71-
_commandsAssembly = Assembly.Load(DesignAssemblyName);
72-
}
66+
_commandsAssembly = DesignAssemblyPath != null
67+
? Assembly.LoadFrom(DesignAssemblyPath)
68+
: Assembly.Load(DesignAssemblyName);
7369
#endif
7470
var reportHandlerType = _commandsAssembly.GetType(ReportHandlerTypeName, throwOnError: true, ignoreCase: false)!;
7571

@@ -109,16 +105,12 @@ protected AssemblyLoadContext AssemblyLoadContext
109105
return _assemblyLoadContext;
110106
}
111107

112-
if (DesignAssemblyPath != null)
108+
AssemblyLoadContext.Default.Resolving += (context, name) =>
113109
{
114-
AssemblyLoadContext.Default.Resolving += (context, name) =>
115-
{
116-
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath)!;
117-
assemblyPath = Path.Combine(assemblyPath, name.Name + ".dll");
118-
return File.Exists(assemblyPath) ? context.LoadFromAssemblyPath(assemblyPath) : null;
119-
};
120-
_assemblyLoadContext = AssemblyLoadContext.Default;
121-
}
110+
var assemblyPath = Path.Combine(AppBasePath, name.Name + ".dll");
111+
return File.Exists(assemblyPath) ? context.LoadFromAssemblyPath(assemblyPath) : null;
112+
};
113+
_assemblyLoadContext = AssemblyLoadContext.Default;
122114

123115
return AssemblyLoadContext.Default;
124116
}
@@ -136,18 +128,13 @@ public override string? EFCoreVersion
136128

137129
Assembly? assembly = null;
138130
#if NET
139-
assembly = AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
131+
assembly = DesignAssemblyPath != null
132+
? AssemblyLoadContext.LoadFromAssemblyPath(DesignAssemblyPath)
133+
: AssemblyLoadContext.LoadFromAssemblyName(new AssemblyName(DesignAssemblyName));
140134
#else
141-
if (DesignAssemblyPath != null)
142-
{
143-
var assemblyPath = Path.GetDirectoryName(DesignAssemblyPath);
144-
assemblyPath = Path.Combine(assemblyPath, DesignAssemblyName + ".dll");
145-
assembly = Assembly.LoadFrom(assemblyPath);
146-
}
147-
else
148-
{
149-
assembly = Assembly.Load(DesignAssemblyName);
150-
}
135+
assembly = DesignAssemblyPath != null
136+
? Assembly.LoadFrom(DesignAssemblyPath)
137+
: Assembly.Load(DesignAssemblyName);
151138
#endif
152139
_efcoreVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
153140
?.InformationalVersion;

src/ef/ef.csproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@
2929
<Reference Include="Microsoft.CSharp" />
3030
<Reference Include="System.Configuration" />
3131
</ItemGroup>
32-
33-
<PropertyGroup>
34-
<!-- Permit targeting `netcoreapp2.0`, see https://github.com/dotnet/efcore/issues/34654 -->
35-
<NoWarn>$(NoWarn);NU1903</NoWarn>
36-
</PropertyGroup>
37-
38-
<ItemGroup>
39-
<!-- Permit targeting `netcoreapp2.0`, see https://github.com/dotnet/efcore/issues/34654 -->
40-
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-7mfr-774f-w5r9" />
41-
</ItemGroup>
4232

4333
<ItemGroup>
4434
<None Update="Generators\BundleProgramGenerator.tt">

0 commit comments

Comments
 (0)