Skip to content

Commit ec0971c

Browse files
[release/8.0.2xx] NGEN Microsoft.DotNet.MSBuildSdkResolver.dll and its dependencies (#17750)
Backport of #17732 to release/8.0.2xx MSBuild.exe currently spends a significant amount of time JITting `Microsoft.DotNet.MSBuildSdkResolver` and its dependencies, see dotnet/msbuild#9303 for details. This PR makes Visual Studio installer add these assemblies to the NGEN queue, which is a necessary condition for eliminating JITting. Just like `Microsoft.Build.*` assemblies, we need to NGEN these with two configurations: vsn.exe so it works in the devenv process, and MSBuild.exe so it works in MSBuild satellite processes.
1 parent cd26afc commit ec0971c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/core-sdk-tasks/GenerateMSBuildExtensionsSWR.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public override bool Execute()
2424

2525
AddFolder(sb,
2626
@"MSBuildSdkResolver",
27-
@"MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver");
27+
@"MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver",
28+
ngenAssemblies: true);
2829

2930
AddFolder(sb,
3031
@"msbuildExtensions",
@@ -39,7 +40,7 @@ public override bool Execute()
3940
return true;
4041
}
4142

42-
private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir)
43+
private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrInstallDir, bool ngenAssemblies = false)
4344
{
4445
string sourceFolder = Path.Combine(MSBuildExtensionsLayoutDirectory, relativeSourcePath);
4546
var files = Directory.GetFiles(sourceFolder)
@@ -55,7 +56,16 @@ private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrIn
5556
{
5657
sb.Append(@" file source=""$(PkgVS_Redist_Common_Net_Core_SDK_MSBuildExtensions)\");
5758
sb.Append(Path.Combine(relativeSourcePath, Path.GetFileName(file)));
58-
sb.AppendLine("\"");
59+
sb.Append('"');
60+
61+
if (ngenAssemblies && file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
62+
{
63+
sb.Append(@" vs.file.ngenApplications=""[installDir]\Common7\IDE\vsn.exe""");
64+
sb.Append(@" vs.file.ngenApplications=""[installDir]\MSBuild\Current\Bin\MSBuild.exe""");
65+
sb.Append(" vs.file.ngenArchitecture=all");
66+
}
67+
68+
sb.AppendLine();
5969
}
6070

6171
sb.AppendLine();
@@ -67,6 +77,7 @@ private void AddFolder(StringBuilder sb, string relativeSourcePath, string swrIn
6777
string newRelativeSourcePath = Path.Combine(relativeSourcePath, subfolderName);
6878
string newSwrInstallDir = Path.Combine(swrInstallDir, subfolderName);
6979

80+
// Don't propagate ngenAssemblies to subdirectories.
7081
AddFolder(sb, newRelativeSourcePath, newSwrInstallDir);
7182
}
7283
}

0 commit comments

Comments
 (0)