Skip to content

Implicit references fail transitively #3046

Closed
@jzabroski

Description

@jzabroski

This issue is effectively the same issue @natemcmaster has reported in dotnet/AspNetCore.Docs#9490 (comment) for .NET Core 2.2 -> 3.0 migrations, but the regression goes back to at least 2.1 -> 2.2 upgrades as well:

Preview 1 Known Issue - workaround for NuGet/Home#7342 - projects which do not start with <Project Sdk="Microsoft.NET.Sdk.Web"> will get compiler or runtime errors due to missing Microsoft.AspNetCore.* assemblies. This is most often the case for test projects and class libraries.

Consider the following project structure:

Source
|
 \ WebApi
   |
   \ WebApi.csproj
Tests
|
 \ WebApi.Tests
  |
   \ WebApi.Tests.csproj

and the following definitions for WebApi.csproj and WebApi.Tests.csproj:

WebApi.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!-- Implicit Version to avoid MSBuild targets warning -->
    <PackageReference Include="Microsoft.AspNetCore.All" />
    <!--<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.3" AllowExplicitVersion="true" />-->
</Project>

WebApi.Tests.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <!-- This could really be any ProjectReference that transitively references a metapackage -->
    <ProjectReference Include="..\WebApi\WebApi.csproj" />
  </ItemGroup>
</Project>

If you build the solution, Tests\WebApi.Tests\obj\project.assets.json will show references to Microsoft.AspNetCore.All metapackage for .NET Core 2.1

The only solution is to use AllowExplicitVersion="true":

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.3" AllowExplicitVersion="true" />

The error message is:

Severity: Error		
Code: CS1705
Description: Assembly 'WebApi' with identity 'WebApi, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Project: WebApi.Tests
File: D:\source\John.Zabroski\Source\WebApi.Tests\CSC
Line:	 1
Suppression State: Active

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions