警告 NETSDK1080:针对 .NET Core 3.0 或更高版本时,不需要对 Microsoft.AspNetCore.App 的 PackageReference

warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher

如何修复在通过 dotnet test 从命令行进行 运行 .NET Core 测试时收到的讨厌警告?

dotnet --version returns回3.1.101.

$ dotnet test
watch : Started
C:\Program Files\dotnet\sdk.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5):
    warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting
    .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically.
    Otherwise, the PackageReference should be replaced with a FrameworkReference.
    [C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj]
C:\Program Files\dotnet\sdk.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5):
    warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting
    .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically.
    Otherwise, the PackageReference should be replaced with a FrameworkReference.
    [C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj]
Test run for C:\github\demo\Demo\SmartHome.API.Test\bin\Debug\netcoreapp3.1\SmartHome.API.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

这是我的 SmartHome.API.Test.csproj 的样子。

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="5.10.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
    <PackageReference Include="MongoDB.Driver" Version="2.10.1" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
    <PackageReference Include="coverlet.collector" Version="1.0.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\SmartHome.API\SmartHome.API.csproj" />
    <ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
  </ItemGroup>

</Project>

这就是 SmartHome.API.csproj,这似乎是问题的根源。

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation" Version="8.6.1" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
    <PackageReference Include="MongoDB.Driver" Version="2.10.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
  </ItemGroup>

</Project>

将包依赖项从 Microsoft.AspNetCore.App (2.2.8) 更改为 SmartHome.API.csproj 中的 FrameworkReference 以引入新包为代价解决了我的问题。

初步修复

+  <ItemGroup>                                                                                                                         
+    <FrameworkReference Include="Microsoft.AspNetCore.App" />                                                                         
+  </ItemGroup>                                                                                                                        
+                                                                                                                                      
   <ItemGroup>                                                                                                                         
     <PackageReference Include="FluentValidation" Version="8.6.1" />                                                                   
-    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />                                                           
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />                                      
     <PackageReference Include="MongoDB.Driver" Version="2.10.1" />                                                                    
   </ItemGroup>                                                                                                                        

新警告

我开始看到一个新警告:

C:\Program Files\dotnet\sdk.1.101\Sdks\Microsoft.NET.Sdk\targets\
  Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(39,5):
warning NETSDK1086: A FrameworkReference for 'Microsoft.AspNetCore.App' was 
  included in the project. This is implicitly referenced by the .NET SDK and you
  do not typically need to reference it from your project. For more information,
  see https://aka.ms/sdkimplicitrefs

最终修复

...所以我最终完全删除了 "Microsoft.AspNetCore.App" 引用。现在构建没有警告了!

即该文件如下所示:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation" Version="8.6.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
    <PackageReference Include="MongoDB.Driver" Version="2.10.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
  </ItemGroup>

</Project>                                                                                                                 

非常感谢提供的修复。 我删除了引用“”,我的构建现在也是 warning-free!! :)

Br, 哈拉尔德