microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
212 stars 83 forks source link

Fix resolving hostfxr #230

Closed YuliiaKovalova closed 10 months ago

YuliiaKovalova commented 10 months ago

Fixes: https://github.com/dotnet/msbuild/issues/9038 https://github.com/microsoft/MSBuildLocator/issues/210 https://github.com/microsoft/MSBuildLocator/issues/200 https://github.com/microsoft/MSBuildLocator/issues/181

This PR solves 2 problems:

  1. Dotnet path resolution
  2. Loading hostfx.(dylib|so) for MAC OS and Linux

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 https://github.com/dotnet/runtime/issues/83774). The path to hostfxr.dylib|so is built based on the pattern /host/fxr//libhostfxr.(dylib|so)

YuliiaKovalova commented 10 months ago

@baronfel please take a look

ladipro commented 10 months ago

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.

YuliiaKovalova commented 10 months ago

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: https://github.com/microsoft/MSBuildLocator/pull/231 please take a look.

and the second part of comment is relevant - I will describe my steps in detail.