dotnet publish doesn't seem to like multiple frameworks
Steps to reproduce
Create a netcoreapp2.0 project. In the csproj file the target framework will be:
<TargetFramework>netcoreapp2.0</TargetFramework>
Create a netstandard2.0 class library, and add support for .net 4.6.1. In the csproj file the target frameworks (plural) will be:
<TargetFrameworks>net461;netstandard2.0</TargetFramework>
Run
dotnet publish --framework netcoreapp2.0
Expected behavior
The solution compiles and it's published.
Actual behavior
There is an error:
Assets file 'c:[path]\ConsoleApp2\ClassLibrary1\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project. [c:[path]\ConsoleApp2\ClassLibrary1\ClassLibrary1.csproj]
Note when there's no multiple frameworks in any of the .csproj files you can mix and match netcoreapp2.0 and netstandard2.0, so this combination:
.csproj file 1:
<TargetFramework>netcoreapp2.0</TargetFramework>
.csproj file 2:
<TargetFramework>netstandard2.0</TargetFramework>
Builds ok with just:
dotnet publish
Which is expected since the netcoreapp2.0 is an implementation of the netstandard2.0. Based on that, should it still work if I just specify "--framework netcoreapp2.0" in the multiple frameworks scenario?
FYI, The workaround is to add netcoreapp2.0 to the target frameworks, but that feels dirty, and makes your .csproj file messy:
<TargetFrameworks>net461;netstandard2.0;netcoreapp2.0</TargetFramework>
Environment data
dotnet --info output:
You mentioned a solution above. If that's the case, that's a known issue tracked here: https://github.com/dotnet/sdk/issues/826.
However, this only happens when building the solution, if you navigate to the console app folder and run dotnet publish --framework netcoreapp2.0, the publish operation succeeds as expected. And, I just tried it out to confirm.
If this still repros to you even when publishing the project directly, please, re-activate or comment.