Closed jzabroski closed 5 years ago
@dsplaisted can you take a look?
It looks like another possible fix is FrameworkReference, per Nate McMaster. Still, not ideal.
@jzabroski This scenario will be fixed in .NET Core 3.0, which will use FrameworkReferences which will flow transitively.
For 2.2, the ASP.NET Core PackageReference does not flow transitively. However, you should be able to add it to the test project (without a version number, the same as in the web project), and it should work correctly. Have you tried that?
@dsplaisted That worked but it's a bit ugly to have to directly include the dependency. I guess it's not much different from how the world worked 4 years ago, so can't complain too much.
Just wondering why this happens so often, and why I'm the one who catches things like this?
One logical reason could be that I define a "cleanfull" target in all my .NET Core projects that does the following:
PS D:\source\John.Zabroski> .\b.ps1 cleanfull
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Clean: Configuration=[Release] Platform=[Any CPU] SolutionOrProjectFile=[D:\source\John.Zabroski\Source
/MySolution.sln]
Clean: Removing NuGet packages directory
Clean: Removing MSTest results directory
Clean: Removing bin and obj directories
This plus an integration test would seem to solve a lot of issues. I'm not trying to give people grief, but I wonder how much time would be saved across Microsoft (and outside Microsoft by its customers!) if such automation existed.
@dsplaisted Can you please review my updated Docs pull request? https://github.com/aspnet/Docs/pull/11688 I tried to incorporate your guidance. I left out stuff about FrameworkReference in 3.0 in case that decision changes before final release.
The transitivity issue isn't related to whether your project is clean. It's just how the reference to ASP.NET works in .NET Core 2.2.
We've been iterating on how the ASP.NET dependency is expressed since .NET Core 1.0. While not ideal, the behavior in 2.2 is improved over 2.1, 2.0, etc. We've made some more fundamental changes for .NET Core 3.0, which we believe will be a big improvement and resolve the issues we've had in previous versions with how the ASP.NET dependency works.
@dsplaisted Updated original post to reflect my full understanding of the issue.
It seems there are two possible positive test cases:
I'll omit negative test cases here, as we don't seem to know the root cause yet. However, the above positive test cases call attention to the fact https://docs.microsoft.com/en-us/dotnet/core/tools/csproj does not cover how <Project Sdk="X">
values for X may or may not influence metapackages.
@dsplaisted Is it possible dotnet host roll forward could be causing you to have difficulty reproducing my issue? How do I share my settings with you? I've just been going through documentation on .NET Core to fully understand what all the knobs are and how they work. See: https://github.com/aspnet/Docs/blob/master/aspnetcore/fundamentals/metapackage-app.md
Quote:
Specifying a version number on the
Microsoft.AspNetCore.App
reference does not guarantee that version of the shared framework will be chosen. For example, suppose version "2.1.1" is specified, but "2.1.3" is installed. In that case, the app will use "2.1.3". Although not recommended, you can disable roll forward (patch and/or minor). For more information regarding dotnet host roll-forward and how to configure its behavior, see dotnet host roll forward.
So, at compile-time in Visual Studio, you (probably) need to account for whether the user has specified DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX
. (I do not have it set, since running $env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX
in PowerShell Core returns $null
).
It also seems the Visual Studio About dialog needs a refresh so that we can consistently nail down why I have this issue you cannot reproduce.
In my case, I have the following Visual Studio "things" installed - but it doesn't list what targeting packs and SDKs I have installed, so you can't really diagnose what roll forward conditions I have:
And here is my dotnet.exe diagnostics:
PS D:\source\GitHub\FluentValidation> dotnet.exe --list-runtimes
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
PS D:\source\GitHub\FluentValidation> dotnet.exe --list-sdks
1.0.4 [C:\Program Files\dotnet\sdk]
2.0.2 [C:\Program Files\dotnet\sdk]
2.0.3 [C:\Program Files\dotnet\sdk]
2.1.2 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.2.105 [C:\Program Files\dotnet\sdk]
PS D:\source\GitHub\FluentValidation> dotnet.exe --version
2.2.105
PS D:\source\GitHub\FluentValidation>
@dsplaisted I built a brand new machine, I put together a full repro of the issue, but noticed some oddities while trying to reproduce the issue. In this case, your guidance to explicitly include an implicitly referenced metapackage without version in the transitive project fails. Here are the errors - I will upload my full repro sln to GitHub for you to look into.
Severity: Error
Code: CS1705
Description: Assembly 'WebApi' with identity 'WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.Core' with identity 'Microsoft.AspNetCore.Mvc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Project: WebApi.Tests
File: D:\source\GitHub\ImplicitReferencesFailTransitively\Sample\WebApi.Tests\CSC
Line: 1
Suppression State: Active
Severity: Warning
Code: MSB3277
Description: Found conflicts between different versions of "Microsoft.AspNetCore.Hosting.Abstractions" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
Project: WebApi.Tests
File: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
Line: 2110
Severity: Warning
Code: MSB3277
Description: Found conflicts between different versions of "Microsoft.AspNetCore.Http.Abstractions" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
Project: WebApi.Tests
File: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
Line: 2110
Severity: Warning
Code: MSB3277
Description: Found conflicts between different versions of "Microsoft.AspNetCore.Mvc.Core" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. Project: WebApi.Tests
File: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
Line: 2110
Severity: Warning
Code: NU1604
Description: Project dependency Microsoft.AspNetCore.Mvc.Core does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.
Project: WebApi.Tests
File: D:\source\GitHub\ImplicitReferencesFailTransitively\Sample\WebApi.Tests\WebApi.Tests.csproj
Line:1
Get-FileHash
of the targets file generating the error, to make sure you and I are comparing apples to apples.
PS C:\Users\john.zabroski> get-filehash "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets"
Algorithm Hash Path
--------- ---- ----
SHA256 0E21AE69F27137BE03D4E94F750B2BCDE542CFE2C0F56ACCA8CF277DA6438BF5 C:\Program Files (x86)\Micros...
Here are my new machines dotnet.exe
sdks, version, etc. I noticed one oddity here - dotnet.exe file version metadata and --version disagree!
PS C:\Users\john.zabroski> dotnet.exe --list-runtimes
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
PS C:\Users\john.zabroski> dotnet.exe --list-sdks
1.1.13 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.2.105 [C:\Program Files\dotnet\sdk]
PS C:\Users\john.zabroski> get-command dotnet.exe
CommandType Name Version Source
----------- ---- ------- ------
Application dotnet.exe 2.2.274... C:\Program Files\dotnet\dotnet.exe
PS C:\Users\john.zabroski> dotnet.exe --version
2.2.105
PS C:\Users\john.zabroski> $env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX -eq $null
True
Here are my Visual Studio Help About Copy Info
@dsplaisted https://github.com/jzabroski/ImplicitReferencesFailTransitively Good luck :)
@jzabroski I was finally able to take a look at your repro. The issue is that only Microsoft.AspNetCore.App and Microsoft.AspNetCore.All are supported as versionless package references. In your test project, you have <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" />
. Replace this with <PackageReference Include="Microsoft.AspNetCore.App" />
, and it should build successfully.
Good catch... I think Resharper may have automatically added a PackageReference for me when it detected I was referencing an MVC Controller.
Sorry, I did not mean to waste your time with the repro - was trying if anything to save you effort. Ah, the art of a good repro :)
As an aside, I am a little perplexed - now if I comment out <PackageReference Include="Microsoft.AspNetCore.App" />
everything just works, even after cleaning my bin and obj directories. I'm completely turned around right now.
I'm on 15.9.10 now.
If I comment out that PackageReference in your repro, I get the following error:
UnitTest1.cs(12,25): error CS0012: The type 'ControllerBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Thanks. That is what I saw before, and am not seeing now. I might just need an eye doctor appointment... 👓
This issues can be closed?
@cfguimaraes Agreed, on .NET SDK 2.2, if I change my reference from
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" />
to
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="[2.2.0,)" />
Then warning goes away. I also no longer get a warning about using a FrameworkReference instead.
Similarly, if I then add <TargetFrameworks>netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
I get the error message:
Severity Code Description Project File Line Suppression State
Error NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.0. Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.0. WebApi.Tests C:\Program Files\dotnet\sdk\2.2.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 137
(@dsplaisted @nguerrera Really great error message, btw! You and your team NAILED IT down to the last detail of creating a separate MSBuild targets file so that the user doesn't even have to click into the file to understand the error is with "TargetFrameworkInference"!)
This issue is effectively the same issue @natemcmaster has reported in https://github.com/aspnet/Docs/issues/9490#issuecomment-442912739 for .NET Core 2.2 -> 3.0 migrations, but the regression goes back to at least 2.1 -> 2.2 upgrades as well:
Consider the following project structure:
and the following definitions for
WebApi.csproj
andWebApi.Tests.csproj
:WebApi.csproj
WebApi.Tests.csproj
If you build the solution,
Tests\WebApi.Tests\obj\project.assets.json
will show references to Microsoft.AspNetCore.All metapackage for .NET Core 2.1The only solution is to use
AllowExplicitVersion="true"
:The error message is: