Skip to content

Commit

Permalink
Reapply "Load Microsoft.DotNet.MSBuildSdkResolver into default load c…
Browse files Browse the repository at this point in the history
…ontext" (#10603)

### Context

Now that dotnet/sdk#39573 has made it into VS, we can finally enable loading `Microsoft.DotNet.MSBuildSdkResolver` by assembly name, as opposed to file path, which makes it possible to use its NGEN image.

### Changes Made

Re-did #9439 which had to be reverted because of the problematic dependency on `Newtonsoft.Json`. The .NET SDK resolver does not depend on `Newtonsoft.Json` anymore. All the other pieces are already in place:
- `Microsoft.DotNet.MSBuildSdkResolver` is NGENed, both for MSBuild.exe and for devenv.exe.
- `devenv.exe.config` contains binding redirects analogous to what's added in this PR.

### Testing

Experimentally inserted into VS and verified that `Microsoft.DotNet.MSBuildSdkResolver` is no longer JITted, saving ~50-100 ms of MSBuild.exe startup time.
  • Loading branch information
ladipro authored Sep 11, 2024
1 parent 227d6c1 commit 1b5033e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
- [Fix oversharing of build results in ResultsCache](https://github.com/dotnet/msbuild/pull/9987)
- [Add ParameterName and PropertyName to TaskParameterEventArgs](https://github.com/dotnet/msbuild/pull/10130)
- [Emit eval props if requested by any sink](https://github.com/dotnet/msbuild/pull/10243)
- [Load Microsoft.DotNet.MSBuildSdkResolver into default load context (MSBuild.exe only)](https://github.com/dotnet/msbuild/pull/10603)

### 17.10
- [AppDomain configuration is serialized without using BinFmt](https://github.com/dotnet/msbuild/pull/9320) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json`. **Please note that [any usage of BinaryFormatter is insecure](https://learn.microsoft.com/dotnet/standard/serialization/binaryformatter-security-guide).**
Expand Down
14 changes: 14 additions & 0 deletions src/Build/BackEnd/Components/SdkResolution/SdkResolverLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ protected virtual IEnumerable<Type> GetResolverTypes(Assembly assembly)
protected virtual Assembly LoadResolverAssembly(string resolverPath)
{
#if !FEATURE_ASSEMBLYLOADCONTEXT
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12))
{
string resolverFileName = Path.GetFileNameWithoutExtension(resolverPath);
if (resolverFileName.Equals("Microsoft.DotNet.MSBuildSdkResolver", StringComparison.OrdinalIgnoreCase))
{
// This will load the resolver assembly into the default load context if possible, and fall back to LoadFrom context.
// We very much prefer the default load context because it allows native images to be used by the CLR, improving startup perf.
AssemblyName assemblyName = new AssemblyName(resolverFileName)
{
CodeBase = resolverPath,
};
return Assembly.Load(assemblyName);
}
}
return Assembly.LoadFrom(resolverPath);
#else
return s_loader.LoadFromPath(resolverPath);
Expand Down
11 changes: 11 additions & 0 deletions src/MSBuild/app.amd64.config
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@
<assemblyIdentity name="Microsoft.VisualStudio.CodeAnalysis.Sdk" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<codeBase version="17.0.0.0" href="..\..\..\Microsoft\VisualStudio\v17.0\CodeAnalysis\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll" />
</dependentAssembly>

<!-- Redirects for SDK resolver components, see https://github.com/dotnet/msbuild/blob/main/documentation/NETFramework-NGEN.md#microsoftdotnetmsbuildsdkresolver for details -->
<qualifyAssembly partialName="Microsoft.DotNet.MSBuildSdkResolver" fullName="Microsoft.DotNet.MSBuildSdkResolver, Version=8.0.100.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" />
<dependentAssembly>
<assemblyIdentity name="Microsoft.DotNet.MSBuildSdkResolver" culture="neutral" publicKeyToken="adb9793829ddae60" />
<codeBase version="8.0.100.0" href="..\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Deployment.DotNet.Releases" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<codeBase version="2.0.0.0" href="..\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.Deployment.DotNet.Releases.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<!-- To define one or more new toolsets, add an 'msbuildToolsets' element in this file. -->
Expand Down
11 changes: 11 additions & 0 deletions src/MSBuild/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@
<assemblyIdentity name="Microsoft.VisualStudio.CodeAnalysis.Sdk" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<codeBase version="17.0.0.0" href="..\..\Microsoft\VisualStudio\v17.0\CodeAnalysis\Microsoft.VisualStudio.CodeAnalysis.Sdk.dll" />
</dependentAssembly>

<!-- Redirects for SDK resolver components, see https://github.com/dotnet/msbuild/blob/main/documentation/NETFramework-NGEN.md#microsoftdotnetmsbuildsdkresolver for details -->
<qualifyAssembly partialName="Microsoft.DotNet.MSBuildSdkResolver" fullName="Microsoft.DotNet.MSBuildSdkResolver, Version=8.0.100.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" />
<dependentAssembly>
<assemblyIdentity name="Microsoft.DotNet.MSBuildSdkResolver" culture="neutral" publicKeyToken="adb9793829ddae60" />
<codeBase version="8.0.100.0" href=".\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Deployment.DotNet.Releases" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<codeBase version="2.0.0.0" href=".\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.Deployment.DotNet.Releases.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<!-- To define one or more new toolsets, add an 'msbuildToolsets' element in this file. -->
Expand Down

0 comments on commit 1b5033e

Please sign in to comment.