c# - 警告 NETSDK1080 : A PackageReference to Microsoft. 面向 .NET Core 3.0 或更高版本时不需要 AspNetCore.App

标签 c# .net asp.net-core .net-core warnings

如何修复我在通过命令行运行 .NET Core 测试时收到的令人讨厌的警告 dotnet test ?
dotnet --version返回 3.1.101 .

$ dotnet test
watch : Started
C:\Program Files\dotnet\sdk\3.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\3.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) 变成 FrameworkReferenceSmartHome.API.csproj以引入一个新的为代价为我解决了这个问题。

初始修复

+  <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\3.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>                                                                                                                 

关于c# - 警告 NETSDK1080 : A PackageReference to Microsoft. 面向 .NET Core 3.0 或更高版本时不需要 AspNetCore.App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60031472/

相关文章:

c# - 实体类对象改变了它的值,尽管它没有改变

java - 单元测试 : Is it bad practice to call public methods (for setup) while testing another method?

c# - 如何在 ASP.Net 应用程序中使用 WMI、C# 将自定义属性添加到 System.Managment 对象?

c# - Azure 下载不完整

.net - WPF 翻译转换

c# - Silverlight 4 RichTextBox 滚动到底部

.net - 将多个数据源添加到datagridview vb.net

jquery - 如何扩展并添加到 .NET Core 中的 IFormFile 接口(interface)。提交ajax请求时需要向序列化数组追加数据

c# - 在 ASP.NET Core 中实现 "JSON Merge Patch"- 区分 null 和未定义属性的最佳方法

c# - C++ (crypto++) 和 C# 加密匹配