dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.73k stars 1.07k forks source link

Question: How do I address "A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll?" #16360

Open myokeeh opened 3 years ago

myokeeh commented 3 years ago

I try-converted a winforms app to .NET and getting a A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll. I'm unsure what to do. Actually I'm unsure what changed last week when I try-converted it (and was working) and now and when I tried to build and run it again.

Target framework on csproj is set <TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

myokeeh commented 3 years ago

@sfoslund, what is actually needed to resolve this? I see it was added in PR https://github.com/dotnet/sdk/pull/15430

I just updated to 5.0.4 from https://dotnet.microsoft.com/download/dotnet/5.0, but didn't resolve the error.

sfoslund commented 3 years ago

5.0.4 is a runtime version, have you tried updating your .NET SDK?

myokeeh commented 3 years ago

Oops. It was the SDK 5.0.201 I downloaded/updated, but didn't have any effect. I just updated to VS 2019 v16.9.2 now, but that didn't help either.

sfoslund commented 3 years ago

Can you provide a binlog reproducing the issue?

myokeeh commented 3 years ago

@sfoslund, see binlog. I'm unsure if it captured what you expect. The viewer just shows "Exceptions. Bad State. Cannot find project." for me. app.zip

sfoslund commented 3 years ago

It looks like the conflicting packages are Microsoft.Windows.Sdk.NET.Ref and Microsoft.Identity.Client. @dsplaisted is it possible @myokeeh needs to update to a 6.0 preview here?

myokeeh commented 3 years ago

Hmm. Microsoft.Identity.Client 4.27.0 is from Feb 19, and this is a recent issue (March).

A bit more info: last Microsoft.Identity.Client version that allows successful build is 4.24.0.

dsplaisted commented 3 years ago

The issue is that the project is referencing (possibly transitively) the Microsoft.Bcl.Build NuGet package. This is an old package that sets AutoUnifyAssemblyReferences to false, which breaks builds for .NET Core.

You should remove the PackageReference to Microsoft.Bcl.Build. If you don't have a direct package reference, try figuring out what is bringing it in transitively, and see if you can upgrade to a newer version that doesn't depend on it anymore.

If that doesn't work, the following should work to reference the package directly but exclude any assets it hase:

<PackageReference Include="Microsoft.Bcl.Build" Version="1.0.21" ExcludeAssets="all" />
myokeeh commented 3 years ago

Good to know! I can confirm removing Microsoft.Bcl.Build allows successful build again. For this legacy project, I'm unsure why that was in there to start. I would not have been able to connect the dots to Microsoft.Bcl.Build from the initial error text I got. Thanks for your help!

dsplaisted commented 3 years ago

Good to know! I can confirm removing Microsoft.Bcl.Build allows successful build again. For this legacy project, I'm unsure why that was in there to start. I would not have been able to connect the dots to Microsoft.Bcl.Build from the initial error text I got. Thanks for your help!

I'm glad to hear it worked. I certainly wouldn't expect someone to figure this out on their own, the Microsoft.Bcl.Build package is modifying some internal build settings and so causing things to fail in unexpected ways.