fsprojects / FAKE

FAKE - F# Make
https://fake.build
Other
1.28k stars 585 forks source link

Fix sdk resolver for net6 assemblies. Using offical .NET release JSON to get runtime version #2625

Closed yazeedobaid closed 2 years ago

yazeedobaid commented 2 years ago

Description

Use Microsoft.Deployment.DotNet.Releases which parses Releases Index to determine .NET runtime version matching resolved SDK specified in a global.json file.

Using RuntimeInformation.FrameworkDescription to determine the runtime version seems to be not guaranteed and how it determines the runtime version is not obvious. I tried it with the following installed SDKs and runtimes:

SDK version -> runtime version 6.0.100-preview.3.21202.5 -> 6.0.0-preview.3.21201.4 6.0.100 -> 6.0.0

Specifying the two SDKs in a global.json file, in both cases, it resolved to 6.0.0-preview.3.21201.4 runtime.

The release index contains DotNet releases, which include released SDKs, runtimes, and all other information. The Microsoft.Deployment.DotNet.Releases package is a typed wrapper around that JSON file.

Credit goes to @baronfel for suggesting it. Thanks

To test different versions of SDK and how SdkAssemblyResolver resolves them correctly, I had to add an environment variable FAKE_SDK_RESOLVER_CUSTOM_DOTNET_PATH to inject DotNet host installation path. Installing DotNet in GitHub actions resulted in overriding the currently used SDK 6.0.100-preview.3.21202.5 since both are installed in the user directory location. And installing it in another place will not let SdkAssemblyResolver pick it up since it looks at the user and system default installation location for DotNet. Adding multiple SDK installations in GitHub actions will solve the problem, but will make it difficult to use FAKE repository directly, since in that case, FAKE will require multiple SDK installations to exist on the machine, which is not practical.

If anyone has better ways to accomplish this, please let me know.

Thanks

TODO

Feel free to open the PR and ask for help