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.64k stars 1.05k forks source link

Publish a WebApplication project using `dotnet publish` will fail when it references a project with Exe outputtype #3307

Open kkwpsv opened 5 years ago

kkwpsv commented 5 years ago

I have two projects. One is a ConsoleApp, the other is WebApplication. And the WebApplication has a ProjectReference to reference the ConsoleApp.

When I publish the WebApplication with --runtime, it has an error like below:

/home/lsj/test/ConsoleApp2/ConsoleApp2.csproj : error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.9, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.

But when I remove the <OutputType>Exe</OutputType> line from the csproj of ConsoleApp, it succeeds.

I have done many tests:

dsplaisted commented 4 years ago

This should actually be fixed in .NET Core 3.0, even once there is a patch version.

For .NET Core 2.x, you should be able to work around the issue by setting TargetLatestRuntimePatch to true in the ConsoleApp. Here's some more information: https://docs.microsoft.com/en-us/dotnet/core/deploying/runtime-patch-selection