![](/img/trans.png)
[英]Warning NETSDK1071 A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of `2.1.6`
[英]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.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\\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.