-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix resolving hostfxr #230
Fix resolving hostfxr #230
Conversation
@baronfel please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not necessarily opposed to it, but this feels like a lot of changes for not very many impactful changes. I generally prefer more targeted changes.
Also, can you separate the framework changes into a separate PR? That feels meaningfully distinct.
+1 on a separate PR for the target framework change. Also, please describe the changes in the initial comment. Ideally everyone would be able to understand how the PR is fixing the issue by reading the description. |
I have moved this change to a separate PR: and the second part of comment is relevant - I will describe my steps in detail. |
5607a03
to
5759980
Compare
bddd4f1
to
b53cd42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I've left a few comments inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One minor comment inline and please obtain at least one more approval.
4f275d1
to
2a6bb81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing blocking IMO is the NuGet dependency at the package level.
// 32-bit architecture | ||
dotnetPath ??= FindDotnetFromEnvironmentVariable("DOTNET_ROOT(x86)", exeName); | ||
var loadContext = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()); | ||
if (loadContext != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is loadContext null? My default assumption would be that there's always at least the default context...is that wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably runtime has some cases for returning null, since SDK also validates it
https://github.com/dotnet/sdk/blob/285888bebe0735d3ad8a4cd0dc1cd1037ba17ed6/src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs#L26
|
||
private static IntPtr HostFxrResolver(Assembly assembly, string libraryName) | ||
{ | ||
var hostFxrLibName = "libhostfxr"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you'd implied it could be libhostfxr or hostfxr by having a regex accepting either—was that wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked that for osx and linux envs - the lib always has this name.
it's called hostfxr on Windows.
throw new InvalidOperationException("Failed to find an appropriate version of .NET Core MSBuild. Call to hostfxr_resolve_sdk2 failed. There may be more details in stderr."); | ||
string? dotnetExePath = GetCurrentProcessPath(); | ||
var isRunFromDotnetExecutable = !string.IsNullOrEmpty(dotnetExePath) | ||
&& Path.GetFileName(dotnetExePath).Equals(ExeName, StringComparison.InvariantCultureIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like something that should be platform-specific, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an execution context-specific - if MsBuild.Locator is invoked in the scope of dotnet.exe, isRunFromDotnetExecutable is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant whether it should be IgnoreCase or not should be platform-specific?
{ | ||
dotnetPath = FindDotnetPathFromEnvVariable("DOTNET_HOST_PATH") | ||
?? FindDotnetPathFromEnvVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR") | ||
?? GetDotnetPathFromPATH(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have one last place where we just look in the expected places, right? Like /usr/bin/dotnet or whatever on linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chet listed the lookup sequence - based on the execution context of MsBuild.Locator, we check different places. More details are in the PR description.
6c38067
to
cede57e
Compare
* Bump Microsoft.NET.Test.Sdk from 15.9.0 to 17.3.1 (#180) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 15.9.0 to 17.3.1. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](microsoft/vstest@v15.9.0...v17.3.1) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump xunit from 2.4.1 to 2.4.2 (#172) Bumps [xunit](https://github.com/xunit/xunit) from 2.4.1 to 2.4.2. - [Release notes](https://github.com/xunit/xunit/releases) - [Commits](xunit/xunit@2.4.1...2.4.2) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump xunit.runner.visualstudio from 2.4.1 to 2.4.5 (#155) Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.4.1 to 2.4.5. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/commits) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Shouldly from 4.0.3 to 4.1.0 (#187) Bumps [Shouldly](https://github.com/shouldly/shouldly) from 4.0.3 to 4.1.0. - [Release notes](https://github.com/shouldly/shouldly/releases) - [Changelog](https://github.com/shouldly/shouldly/blob/master/BREAKING%20CHANGES.txt) - [Commits](shouldly/shouldly@v4.0.3...4.1.0) --- updated-dependencies: - dependency-name: Shouldly dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Forgind <[email protected]> * Bump Microsoft.VisualStudio.Setup.Configuration.Interop (#186) Bumps Microsoft.VisualStudio.Setup.Configuration.Interop from 1.16.30 to 3.3.2180. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Setup.Configuration.Interop dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Microsoft.VisualStudio.SDK.EmbedInteropTypes Bumps Microsoft.VisualStudio.SDK.EmbedInteropTypes from 15.0.21 to 15.0.36. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.SDK.EmbedInteropTypes dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * Enabling CodeQL (#190) Enables CodeQL in build pipeline * Update xml doc comments (#193) Update xml doc comments * Bump Shouldly from 4.1.0 to 4.2.1 Bumps [Shouldly](https://github.com/shouldly/shouldly) from 4.1.0 to 4.2.1. - [Release notes](https://github.com/shouldly/shouldly/releases) - [Changelog](https://github.com/shouldly/shouldly/blob/master/BREAKING%20CHANGES.txt) - [Commits](shouldly/shouldly@4.1.0...4.2.1) --- updated-dependencies: - dependency-name: Shouldly dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump Microsoft.VisualStudio.Setup.Configuration.Interop Bumps Microsoft.VisualStudio.Setup.Configuration.Interop from 3.3.2180 to 3.6.2115. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Setup.Configuration.Interop dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump Nerdbank.GitVersioning from 3.5.107 to 3.6.133 Bumps [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) from 3.5.107 to 3.6.133. - [Release notes](https://github.com/dotnet/Nerdbank.GitVersioning/releases) - [Commits](dotnet/Nerdbank.GitVersioning@v3.5.107...v3.6.133) --- updated-dependencies: - dependency-name: Nerdbank.GitVersioning dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump Microsoft.NET.Test.Sdk from 17.3.1 to 17.6.2 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.3.1 to 17.6.2. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.3.1...v17.6.2) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Update Releasing_MSBuildLocator.md * Bump xunit.runner.visualstudio from 2.4.5 to 2.5.0 (#223) Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.4.5 to 2.5.0. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](xunit/visualstudio.xunit@v2.4.5...2.5.0) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Microsoft.NET.Test.Sdk from 17.6.2 to 17.6.3 (#221) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.6.2 to 17.6.3. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.6.2...v17.6.3) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump xunit from 2.4.2 to 2.5.0 (#222) Bumps [xunit](https://github.com/xunit/xunit) from 2.4.2 to 2.5.0. - [Commits](xunit/xunit@2.4.2...2.5.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Make Unregister a no-op Fixes #77 (#204) * Make Unregister a no-op * Change comment * Specify not to show Unregister * Sort usings --------- Co-authored-by: Forgind <[email protected]> * Validate dotnet executable exists (#202) * Validate dotnet executable exists * PR comment * Update src/MSBuildLocator/DotNetSdkLocationHelper.cs Co-authored-by: Ladi Prosek <[email protected]> * Simplify logic Also avoids an unnecessary File.Exists check on Windows --------- Co-authored-by: Forgind <[email protected]> Co-authored-by: Ladi Prosek <[email protected]> * Bump Microsoft.NET.Test.Sdk from 17.6.3 to 17.7.0 (#226) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.6.3 to 17.7.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.6.3...v17.7.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump Microsoft.VisualStudio.Setup.Configuration.Interop (#227) Bumps Microsoft.VisualStudio.Setup.Configuration.Interop from 3.6.2115 to 3.7.2175. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Setup.Configuration.Interop dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Respect DOTNET_ROOT (#225) * Respect DOTNET_ROOT * DOTNET_ROOT is a folder. Also, DOTNET_ROOT(x86) * PR Feedback --------- Co-authored-by: Forgind <[email protected]> * Bump Microsoft.NET.Test.Sdk from 17.7.0 to 17.7.1 (#228) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.7.0 to 17.7.1. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.7.0...v17.7.1) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * upgrade core version to net6.0 (#231) * upgrade framework version + fix issue with path extraction from environment variable * fix review comments * Fix resolving hostfxr for Mac OS and Linux envs (#230) * add setting of "DOTNET_HOST_PATH" env variable (#235) * Fix hostfx resolving issue in some Mac machines (#236) * Add diagnostic logging, and address issues in the code. * Update the fix: 1, it turns out DotnetPath is the folder path. It just sets DOTNET_HOST_PATH incorrectly DOTNET_HOST_PATH is a file path, which is different than DOTNET_ROOT 2, Fix DOTNET_HOST_PATH handling, which broke the application when it sets to a folder. * use StringComparison.OrdinalIgnoreCase to compare file name maybe should use platform dependent comparison, but it looks like the rest of code is doing that. * do not create new instance on each call. * Further hardern the logic inside HostFxrResolver Adds more logging and handles empty folder. * delete unnecessary logging. * Additional logging. * Throw errors instead of logging it. --------- Co-authored-by: Lifeng Lu <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Forgind <[email protected]> Co-authored-by: MichalPavlik <[email protected]> Co-authored-by: Forgind <[email protected]> Co-authored-by: Ladi Prosek <[email protected]> Co-authored-by: Lifeng Lu <[email protected]> Co-authored-by: Lifeng Lu <[email protected]>
Fixes:
dotnet/msbuild#9038
#210
#200
#181
This PR solves 2 problems:
In order to resolve dotnet path, we probe different sources:
Case: MSBuild.Locator is called from dotnet.exe, check DOTNET_ROOT env var -> current process path
Case: MSBuild.Locator is called in apphost, check DOTNET_ROOT env var -> DOTNET_HOST_PATH -> DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR -> PATH
If the path can't be extracted, an exception is thrown.
When DotnetPath is resolved, we create a subscription on ResolvingUnmanagedDll event when hostfx is requested, if it isn't not loaded in context (the possible reason is described here dotnet/runtime#83774).
The path to hostfxr.dylib|so is built based on the pattern <dotnet_path>/host/fxr//libhostfxr.(dylib|so)