Search code examples
c#.net.net-6.0publish.net-standard-2.0

dotnet publish self contained .net6 project referencing netstandard2.0 library not working


In Visual Studio I create a sample WPF project targeting .NET6, then I create a library targeting .NET Standard 2.0 which I reference from the .NET6 project.

Then when I run dotnet publish WpfAfpp1.sln --framework net6.0-windows,

I get this error:

error NETSDK1005: Assets file 'C:\Users\STEMAL\source\repos\WpfApp1\ClassLibrary1\obj\project.assets.json' doesn't have a target for 'net6.0-windows'. Ensure that restore has run and that you have included 'net6.0-windows' in the TargetFrameworks for your project. [C:\Users\STEMAL\source\repos\WpfApp1\ClassLibrary1\ClassLibrary1.csproj]

Why does this happen? Isn't netstandard2.0 supposed to be supported by .NET 6?

The library should preferably just have the netstandard2.0 target, and the reason I am using the --framework configuration on dotnet publish is because I have some multi targeted projects in my solution.


Solution

  • You can only publish a project (and not a solution). Try :

    dotnet publish WpfAfpp1.csproj --framework net6.0-windows