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
218 stars 83 forks source link

Loading net5.0 Assemblies Shouldn't Happen When Running < net5.0 #92

Closed benvillalobos closed 3 years ago

benvillalobos commented 4 years ago

Related issue and repro: https://github.com/dotnet/msbuild/issues/5600

When targeting netcore3.1 and loading an assembly that depends on a net5.0 assembly (in this case Microsoft.Build.NuGetSdkResolver depending on System.Runtime version 5.0), it can fail to load.

It fails on line 118 of SdkResolverService

                 result = (SdkResult)sdkResolver.Resolve(sdk, context, resultFactory);
"System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.Build.NuGetSdkResolver.NuGetSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
   at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive)

"

We should consider changing MSBuildLocator to NOT return .NET Core SDK's that are newer than the current .NET Core runtime.

jzabroski commented 4 years ago

Innocent question: How would you know, in general, the current .NET Core runtime version is "less than" a particular installed version? What logic do you suggest? What about if .NET Core adopts an Android-style API levels concept? That is what net472 and netstandard2.0 tried, but it was an utter failure for OOB scenarios. Maybe this will work for In-Box scenarios since Microsoft can create a closed world where the "less than" operator is statically known and can fully regression test the SdkReference universe because its known via double secret handshake. But you can't extend this to plug-ins that use a PackageReference, right?

AArnott commented 3 years ago

This is breaking our dotnet mpc tool: https://github.com/neuecc/MessagePack-CSharp/issues/1102

viktorveis commented 3 years ago

This issue is breaking the Q# language server if .NET 5.0 is installed: https://github.com/microsoft/qsharp-compiler/issues/737