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.75k stars 1.07k forks source link

Publish and run fail on app with project reference to netstandard2.0 class library #8378

Closed mikeharder closed 4 years ago

mikeharder commented 7 years ago

In CLI 2.0.0-preview2-006391 or later, dotnet publish -f fails on an app with a project reference to a netstandard2.0 class library.

Repro Steps

  1. git clone https://github.com/mikeharder/NetCoreProjectReference
  2. cd NetCoreProjectReferece\console_netcoreapp20_net46
  3. dotnet restore
  4. dotnet publish -f netcoreapp2.0
MSBUILD : error NU1201: Project classlib_netstandard20 is not compatible with net461 (.NETFramework,Version=v4.6.1).
Project classlib_netstandard20 supports: netcoreapp2.0 (.NETCoreApp,Version=v2.0) 
[C:\Git\NetCoreProjectReference\console_netcoreapp20_net461\console_netcoreapp20_net461.csproj]
  1. dotnet publish -f net461
C:\Temp\dotnet-sdk-2.0.0-preview2-006391-win-x64\sdk\2.0.0-preview2-006391\Sdks\Microsoft.NET.Sdk\build\
Microsoft.PackageDependencyResolution.targets(164,5): error :
Assets file 'C:\Git\NetCoreProjectReference\classlib_netstandard20\obj\project.assets.json' doesn't have a target
for '.NETStandard,Version=v2.0'. Ensure you have included 'netstandard2.0' in the TargetFrameworks for your project. 
[C:\Git\NetCoreProjectReference\classlib_netstandard20\classlib_netstandard20.csproj]
  1. Above publish commands work if the --no-restore parameter is added.
livarcocc commented 7 years ago

We have a proposal to fix this and I will try it out tonight.

The proposal is to not pass forward to implicit restore the -f/--framework parameter.

mikeharder commented 7 years ago

Issue also impacts dotnet run.