-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Issue Description
After upgrading to version 17.12.* and 17.14.* from 17.8.3, when attempting to programmatically build a project that references any SDK, i.e.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net9.0</TargetFramework> <RootNamespace>MsBuild.Test</RootNamespace> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> <PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> <PackageReference Include="Microsoft.Build" Version ="17.14.8" ExcludeAssets="runtime"/> <PackageReference Include="Microsoft.Build.Locator" Version ="1.9.1"/> </ItemGroup> </Project>
I'm continually met with the following exception at runtime:
The SDK resolver assembly "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.dll" could not be loaded. Could not load file or assembly 'Microsoft.DotNet.MSBuildSdkResolver, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Inner Exception:
Message: Could not load file or assembly 'Microsoft.DotNet.MSBuildSdkResolver, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source: System.Private.CoreLib
Stack Trace: at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.Build.BackEnd.SdkResolution.SdkResolverLoader.LoadResolverAssembly(String resolverPath)
at Microsoft.Build.BackEnd.SdkResolution.SdkResolverLoader.LoadResolvers(String resolverPath, ElementLocation location, List`1 resolvers)
Steps to Reproduce
I've got a dummy test here running the decompiled code for the resolver, which repros the failure I'm seeing. This code was pulled from https://github.com/dotnet/msbuild/blob/main/src/Build/BackEnd/Components/SdkResolution/SdkResolverLoader.cs :
[TestMethod]
public void ResolverTest()
{
// Default resolver location found from MSBuild using
// MSBuildLocator.RegisterMsBuildPath(C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\MSBuild\\Current\\Bin);
string resolverPath = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\MSBuild\\Current\\Bin\\SdkResolvers\\Microsoft.DotNet.MSBuildSdkResolver\\Microsoft.DotNet.MSBuildSdkResolver.dll";
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(resolverPath);
if (fileNameWithoutExtension.Equals("Microsoft.DotNet.MSBuildSdkResolver", StringComparison.OrdinalIgnoreCase))
{
Assert.ThrowsException<FileNotFoundException>(() =>
{
var i = Assembly.Load(new AssemblyName(fileNameWithoutExtension)
{
CodeBase = resolverPath
});
}, "Expected Assembly.Load to fail");
}
}`
Expected Behavior
MsBuild can be used to programmatically build projects containing SDK references
Actual Behavior
Building projects with SDK references results in a failure related to the Microsoft.DotNet.MsBuildSdkResolver
Analysis
I believe the issue lies on line 241 here: https://github.com/dotnet/msbuild/blob/main/src/Build/BackEnd/Components/SdkResolution/SdkResolverLoader.cs
Versions & Configurations
Current Version:
MSBuild version 17.14.23+b0019275e for .NET Framework 17.14.23.42201
SDKS installed:
2.1.202 [C:\Program Files\dotnet\sdk] 2.1.526 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.214 [C:\Program Files\dotnet\sdk] 6.0.136 [C:\Program Files\dotnet\sdk] 6.0.321 [C:\Program Files\dotnet\sdk] 6.0.428 [C:\Program Files\dotnet\sdk] 8.0.120 [C:\Program Files\dotnet\sdk] 9.0.305 [C:\Program Files\dotnet\sdk]