Skip to content

Conversation

@ladipro
Copy link
Member

@ladipro ladipro commented Nov 20, 2023

Fixes #9303

Context

After a new version of VS.Redist.Common.Net.Core.SDK.MSBuildExtensions is inserted into VS, a native image for Microsoft.DotNet.MSBuildSdkResolver will be generated, both for devenv.exe and MSBuild.exe (see dotnet/installer#17732).

We currently load SDK resolvers using Assembly.LoadFrom on .NET Framework, which disqualifies it from using native images even if they existed. This PR makes us use the native image.

Changes Made

Added a code path to use Assembly.Load to load resolver assemblies. The call is made such that if the assembly cannot be found by simple name, it falls back to loading by path into the load-from context, just like today. The new code path is enabled only for Microsoft.DotNet.MSBuildSdkResolver under a change-wave check.

Testing

Experimental insertions.

Notes

Using qualifyAssembly in the app config has the advantage of keeping everything field-configurable, i.e. in the unlikely case that a custom build environment will ship with a different version of the resolver, it will be possible to compensate for that by tweaking the config file. The disadvantage is that the same qualifyAssembly will need to be added to devenv.exe.config because .pkgdef doesn't support this kind of entry, to my best knowledge. It should be a one-time change, though, because we have frozen the version of Microsoft.DotNet.MSBuildSdkResolver to 8.0.100.0.

@AR-May AR-May self-requested a review November 28, 2023 15:19
@ladipro ladipro requested a review from JanKrivanek November 28, 2023 15:26
@rainersigwald
Copy link
Member

Should this go to 17.9?

Copy link
Member Author

@ladipro ladipro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go to 17.9?

I believe so. Because the SDK is now attempting to NGEN the resolver against MSBuild.exe but the app.config is missing the requisite redirects, PerfDDRITs have flagged a regression in "invalid assembly count". Merging this into 17.9 would prevent that regression (however insignificant) to be shipped publicly.

ladipro added a commit to dotnet/sdk that referenced this pull request Dec 8, 2023
…eline (#37381)

As pointed out in dotnet/msbuild#9439 (comment), we have to be careful when changing the set of dependencies of the SDK resolver assembly as it may impact binding redirects in MSBuild's app.config.

This PR adds a simple post-build step which compares the dependencies of the just-built assembly with a baseline.

Co-authored-by: Rainer Sigwald <[email protected]>
@ladipro ladipro changed the base branch from main to vs17.9 December 8, 2023 15:51
@ladipro ladipro force-pushed the 9303-sdk-resolver branch 2 times, most recently from aa68c3a to e3b2480 Compare December 8, 2023 15:52
@ladipro
Copy link
Member Author

ladipro commented Dec 8, 2023

I have retargeted the PR to 17.9.

@ladipro ladipro enabled auto-merge (squash) December 13, 2023 16:04
@ladipro ladipro merged commit 6257b8e into dotnet:vs17.9 Dec 13, 2023
JanKrivanek added a commit to JanKrivanek/msbuild that referenced this pull request Dec 22, 2023
ladipro added a commit to ladipro/msbuild that referenced this pull request Mar 12, 2024
rainersigwald pushed a commit that referenced this pull request Mar 13, 2024
…ntext" (#9857)

* Revert "Load Microsoft.DotNet.MSBuildSdkResolver into default load context (MSBuild.exe only) (#9439)"

This reverts commit 6257b8e.

* Bump version
YuliiaKovalova pushed a commit that referenced this pull request Mar 14, 2024
…ntext" (#9857) (#9861)

* Revert "Load Microsoft.DotNet.MSBuildSdkResolver into default load context (MSBuild.exe only) (#9439)"

This reverts commit 6257b8e.

* Bump version

Co-authored-by: Ladi Prosek <[email protected]>
ladipro added a commit that referenced this pull request Sep 11, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: MSBuild.exe spends 300 ms JITting Microsoft.DotNet.MSBuildSdkResolver.dll

3 participants