简体   繁体   English

Warning.NETSDK1071 对“Microsoft.AspNetCore.App”的 PackageReference 指定了“2.1.6”的版本

[英]Warning NETSDK1071 A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of `2.1.6`

I have the following warning我有以下警告

 Severity   Code    Description Project File    Line    Suppression State
Warning NETSDK1071  A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of `2.1.6`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs    MyApi   C:\Program Files\dotnet\sdk\2.2.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets   153 

I tried removing the reference by editing the project file and then adding the nuget package, however when I did this a lot of references no longer worked correctly.我尝试通过编辑项目文件然后添加 nuget package 来删除引用,但是当我这样做时,很多引用不再正常工作。

I note the error is mentioning sdk\2.2 which I did install recently on my computer but there is no reference to it in the project file.我注意到错误提到了我最近在我的计算机上安装的 sdk\2.2,但在项目文件中没有引用它。

I am using VS2017 15.9.5我正在使用 VS2017 15.9.5

There's a few ways around this.有几种方法可以解决这个问题。

  • If you include the PackageReference but remove the Version attribute, it should make the warning go away.如果您包含PackageReference但删除了Version属性,它应该会使警告消失。 This is because it is a metapackage , which (simply put) is a type of package that gets the version based on your framework version, more here: https://docs.microsoft.com/en-us/dotnet/core/packages#metapackages这是因为它是一个metapackage ,它(简单地说)是一种基于你的框架版本获取版本的包,更多在这里: https : //docs.microsoft.com/en-us/dotnet/core/packages #元包

  • To disable the warnings, add AllowExplicitVersion :要禁用警告,请添加AllowExplicitVersion

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.11" >
  <AllowExplicitVersion>true</AllowExplicitVersion> 
</PackageReference>

More here: https://github.com/dotnet/sdk/issues/2602更多信息: https : //github.com/dotnet/sdk/issues/2602

I ran into a similar situation creating a new xUnit Test Project (.NET Core).我在创建一个新的 xUnit 测试项目 (.NET Core) 时遇到了类似的情况。 When I added a reference to an existing ASP.NET Core Web App project, I got:当我添加对现有 ASP.NET Core Web App 项目的引用时,我得到:

Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277 : Found conflicts between different versions of : Microsoft.Common.CurrentVersion.targets(2106,5):警告MSB3277发现不同版本之间的冲突

  • Microsoft.AspNetCore.Authorization Microsoft.AspNetCore.Authorization
  • Microsoft.AspNetCore.Cors微软.AspNetCore.Cors
  • Microsoft.AspNetCore.Diagnostics.Abstractions Microsoft.AspNetCore.Diagnostics.Abstractions
  • Microsoft.AspNetCore.Mvc微软.AspNetCore.Mvc
  • Microsoft.AspNetCore.Mvc.Abstractions Microsoft.AspNetCore.Mvc.Abstractions
  • Microsoft.AspNetCore.Mvc.Core Microsoft.AspNetCore.Mvc.Core
  • Microsoft.AspNetCore.Mvc.Formatters.Json Microsoft.AspNetCore.Mvc.Formatters.Json
  • Microsoft.AspNetCore.Mvc.RazorPages Microsoft.AspNetCore.Mvc.RazorPages
  • Microsoft.AspNetCore.Mvc.ViewFeatures Microsoft.AspNetCore.Mvc.ViewFeatures
  • Microsoft.AspNetCore.Razor.Runtime Microsoft.AspNetCore.Razor.Runtime
  • Microsoft.AspNetCore.Routing Microsoft.AspNetCore.Routing

I did not understand how there could be conflicts when I did not find any references to Microsoft.AspNetCore.App NuGet package in my xUnit project.当我在 xUnit 项目中没有找到对 Microsoft.AspNetCore.App NuGet 包的任何引用时,我不明白怎么会发生冲突。

I eliminated these version conflicts by adding the Microsoft.AspNetCore.App to my xUnit Test project.我通过将Microsoft.AspNetCore.App添加到我的 xUnit 测试项目来消除这些版本冲突。

At this point, I started getting the explicit version reference warning ( NETSDK1071 ).此时,我开始收到显式版本参考警告( NETSDK1071 )。

NuGet Package Manager and Package Manager Console within Visual Studio will both add the version attribute to Microsoft.AspNetCore.App when installing the package.安装包时,Visual Studio 中的 NuGet 包管理器和包管理器控制台都会将版本属性添加到 Microsoft.AspNetCore.App。 You may remove the version attribute by editing your .csproj file.您可以通过编辑 .csproj 文件来删除版本属性。 This should eliminate the NETSDK1071 warning.这应该会消除 NETSDK1071 警告。

Note that if you do remove the version attribute, then NuGet Package Manager will disable the [Uninstall] + [Update] buttons and state: "- implicitly referenced by an SDK..." .请注意,如果您确实删除了 version 属性,则 NuGet 包管理器将禁用 [Uninstall] + [Update] 按钮并声明: “-由 SDK 隐式引用...”

At this point, I am not getting any warnings.在这一点上,我没有收到任何警告。

There is a lot of chatter and some tldr;有很多喋喋不休和一些 tldr; documentation related to this issue.与此问题相关的文档。 FWIW, here are a couple of succinct resources that I think warrant highlighting: FWIW,这里有一些我认为值得强调的简洁资源:

Microsoft.AspNetCore.App metapackage for ASP.NET Core 2.1 or later 适用于 ASP.NET Core 2.1 或更高版本的 Microsoft.AspNetCore.App 元包

@nguerrera summarized the the situation very well: @nguerrera 很好地总结了情况:

It is for all tests, or even all non-web projects that have a reference to a web project.它适用于所有测试,甚至所有引用 Web 项目的非 Web 项目。 It is not really a workaround in that the web reference did not flow transitively in .NET Core 2.x.这并不是真正的解决方法,因为 Web 引用在 .NET Core 2.x 中没有传递。 You need to add it, and you should add it without the version so that the SDK can pick the correct version to avoid conflicts.您需要添加它,并且您应该在没有版本的情况下添加它,以便 SDK 可以选择正确的版本以避免冲突。

Better news: starting with .NET Core 3.0, the web reference will flow transitively and you can reference a web project from a test project without any other steps.更好的消息:从 .NET Core 3.0 开始,Web 引用将传递传递,您可以从测试项目引用 Web 项目,而无需任何其他步骤。 So I am closing this.所以我要关闭这个。 The design of 2.x cannot be changed, but we specifically designed things in 3.0 to have transitive Framework References, and this was a motivating scenario for that. 2.x 的设计无法改变,但我们在 3.0 中专门设计了具有可传递框架引用的东西,这是一个激励方案。

And here are a couple of tldr;这里有几个 tldr; conversations:对话:

Does not cover Microsoft.AspNet.Core.All #8691不包括 Microsoft.AspNet.Core.All #8691

Version conflicts in test project depending on a Microsoft.AspNetCore.App project #2253 测试项目中的版本冲突取决于 Microsoft.AspNetCore.App 项目 #2253

I had a similar issue with the error code MB2322.我遇到了错误代码 MB2322 的类似问题。 Fixed this by removing the version from the tag and adding the version to my Packages.props file in the src folder for the project.通过从标签中删除版本并将版本添加到项目 src 文件夹中我的 Packages.props 文件来修复此问题。

So to translate here in terms of your project, the PackageReference portion you already have would simply have the version removed:因此,要根据您的项目在此处进行翻译,您已经拥有的 PackageReference 部分只需删除版本即可:

<PackageReference Include="Microsoft.AspNetCore.App" />

And in your Packages.props file, you'd add:在您的 Packages.props 文件中,您将添加:

<PackageReference Update="Microsoft.AspNetCore.App" Version="[whichever version you are using here]"/>

For Developers working on Nopcommerce.对于从事 Nopcommerce 的开发人员。

I was having the issue with Nopcommerce Project v(2.2).我遇到了 Nopcommerce Project v(2.2) 的问题。 To resolve, you have to make an edit inside Nop.Core.csproj file.要解决,您必须在 Nop.Core.csproj 文件中进行编辑。

change :改变 :

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.5" />

with :和 :

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.5">
      <AllowExplicitVersion>true</AllowExplicitVersion>
</PackageReference>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告 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 NETSDK1073:无法识别 FrameworkReference 'Microsoft.AspNetCore.App' - NETSDK1073: The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized 修复指定的框架&#39;Microsoft.AspNetCore.App&#39;版本&#39;2.1.1&#39; - Fixing The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' 未找到 Microsoft.NetCore.App 或 Microsoft.AspNetCore.App 的指定版本 - The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found 找不到任何兼容的框架版本找不到指定的框架&#39;Microsoft.AspNetCore.App&#39;版本&#39;2.2.0&#39; - It was not possible to find any compatible framework version The specified framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found 在Visual Studio 7.5 Mac中找不到指定的框架&#39;Microsoft.AspNetCore.App&#39;版本&#39;2.1.0&#39; - The specified framework 'Microsoft.AspNetCore.App', version '2.1.0' was not found docker in visual studio 7.5 mac PackageReference Microsoft.AspNetCore.App 从核心 2.2 到核心 3 和 3.1 的方式变化 - PackageReference Microsoft.AspNetCore.App change of manner from core 2.2 to core 3 & 3.1 Docker - 在构建时找不到框架 microsoft.AspNetCore.App,版本 &#39;3.1&#39;0 - Docker - The framework microsoft.AspNetCore.App, version '3.1'0 was not found on build 没有适用于指定 RuntimeIdentifier android-x86 的 Microsoft.AspNetCore.App 运行时包 - There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier android-x86 控制台应用程序已更新为 .Net Core 3.1 错误找不到框架“Microsoft.AspNetCore.App”,版本“3.1.0” - Console App Updated to .Net Core 3.1 Error The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM