簡體   English   中英

警告 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返回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) 中的包依賴項更改為SmartHome.API.csprojFrameworkReference為我解決了這個問題,但代價是引入了一個新的問題。

初始修復

+  <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>                                                                                                                 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM