Repro
repro.zip
Create two projects:
Run dotnet restore with the 2.1.301 SDK or newer
Result
Restore fails
/private/tmp/console1/test/test.csproj : error NU1605: Detected package downgrade: Microsoft.NETCore.App from 2.1.1 to 2.1.0. Reference the package directly from the project to select a different version. [/private/tmp/console1/console1.sln]
/private/tmp/console1/test/test.csproj : error NU1605: test -> src -> Microsoft.NETCore.App (>= 2.1.1) [/private/tmp/console1/console1.sln]
/private/tmp/console1/test/test.csproj : error NU1605: test -> Microsoft.NETCore.App (>= 2.1.0) [/private/tmp/console1/console1.sln]
Restore failed in 396.65 ms for /private/tmp/console1/test/test.csproj.
Workarounds
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> to test.csproj ( suggested by @dsplaisted )<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion> to test.csproj<RuntimeIdentifier>win-x64</RuntimeIdentifier> and <OutputType>exe</OutputType> to test.csproj<RuntimeIdentifier> to <RuntimeIdentifiers> (plural) in src.csprojDetails
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /Users/namc/.dotnet/sdk/2.1.301/
cc @dsplaisted
The workaround I would suggest is to set TargetLatestRuntimePatch to true in the test project.
Some related info: https://docs.microsoft.com/en-us/dotnet/core/deploying/runtime-patch-selection
Good suggestion. I added to the list of workarounds above.
How hard would it be to automatically lift to latest when a ProjectReference is using latest (2.1.1) instead of default (2.1.0)?
One more idea: what if we set PrivateAssets=All even when OutputType == exe? Based on this comment, it seems like we don't generally need Microsoft.NETCore.App in the .nuspec with the notable exception (and edge case) of '$(PackageType)' == 'DotnetCliTool'
I filed #2204 to always set PrivateAssets=All, but we were worried that changing it would break cases where it's needed.
Is DotnetCliTool the only scenario where the reference is needed? Even then, I don't think there is an explicit PackageType or other declaration in the project that it is a DotnetCliTool.
How hard would it be to automatically lift to latest when a ProjectReference is using latest (2.1.1) instead of default (2.1.0)?
Prohibitively hard, I think.
Is DotnetCliTool the only scenario where the reference is needed?
As far as I can tell, yes, this is the only scenario we support. We should be able to use $(PackageType) to detect this. example: https://github.com/aspnet/DotNetTools/blob/2.0.2/src/Microsoft.DotNet.Watcher.Tools/Microsoft.DotNet.Watcher.Tools.csproj#L12
In my case, even though I specified the RuntimeIdentifier on the src project, I actually wanted the app to be published in Framework Dependent mode. So my solution was to set <SelfContained>false</SelfContained> in the project. This prevented the test and src projects from using different runtimes.
This should be fixed in the 2.2.100 SDK with #2395
Is 2.2.100 released? I don't see it in the Releases.
It is not. It will be a couple months before it is official out.
You can try our previews though :) You should be able to use a 2.2.100 Preview SDK to build your netcoreapp2.1 projects.
Most helpful comment
The workaround I would suggest is to set
TargetLatestRuntimePatchto true in the test project.Some related info: https://docs.microsoft.com/en-us/dotnet/core/deploying/runtime-patch-selection