предупреждение NETSDK1080: Ссылка PackageReference на Microsoft.AspNetCore.App не требуется при нацеливании. NET Core 3.0 или выше - PullRequest
3 голосов
/ 03 февраля 2020

Как исправить неприятное предупреждение, которое я получаю при запуске. NET Тесты ядра из командной строки через 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>

1 Ответ

6 голосов
/ 03 февраля 2020

Изменение зависимости пакета с Microsoft.AspNetCore.App (2.2.8) на FrameworkReference в SmartHome.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>                                                                                                                 
...