gpt4 book ai didi

.net - NuGetPackageImportStamp 的用途是什么?

转载 作者:行者123 更新时间:2023-12-03 05:29:35 24 4
gpt4 key购买 nike

将某些 NuGet 包添加到项目时,有时 .csproj 文件的第一个属性组中会出现一个奇怪的项目。

<PropertyGroup>
...
<NuGetPackageImportStamp>3d051ef3</NuGetPackageImportStamp>
</PropertyGroup>

标记每次都不同,并且看起来不连续。

我找不到任何对 <NuGetPackageImportStamp> 的引用在 NuGet 文档中。它的用途是什么?它是如何工作的?有必要吗?

每次都会添加此内容的一个包是 StyleCop.MSBuild ,至少在当前的 4.7.49 版本中是这样。只需将该包添加到新项目中,您就会看到这个神秘项目出现在您的项目文件中。

最佳答案

NuGetPackageImportStamp 是 Visual Studio 2013 及更高版本无法检测 NuGet 包添加或删除 MSBuild 导入的解决方法。

旧版本的 Visual Studio 不需要此解决方法。即使在 Visual Studio 2013 中,也可以安全地删除该属性:如果关闭并重新打开解决方案,Visual Studio 将重新加载导入的 MSBuild 目标。

NuGet source code显示当包添加或删除 MSBuild 导入时,NuGet 会添加此属性。它每次都使用新的 GUID。 Visual Studio 2013 检测到项目已更改并提供重新加载。仅添加或删除 MSBuild 导入不足以让 Visual Studio 2013 了解项目在运行时已更改,这正是 NuGet 通过此解决方法解决的问题。

StyleCop.MSBuild NuGet 包包含自定义 MSBuild 目标,因此添加或删除此 NuGet 包将导致添加此属性。

<小时/>

更新:Matt Ward's comment是正确且重要的。

There is still code in NuGet that adds the NuGet package stamp and the code no longer checks for Visual Studio 2013.

以下是我的底线建议:

  • 使用 Visual Studio 或 Powershell 创建新项目。
  • 当您更新旧的 csproj 并且它不起作用时,请将此旧的 csproj 与您使用 Visual Studio 或 Powershell 创建的新的工作 csproj 进行比较。如果新的工作 csproj 使用 <NuGetPackageImportStamp>指令,然后将其添加到旧的损坏的 csproj 中,看看是否可以解决问题; 无论您使用的是哪个 Visual Studio 版本。
  • 如果您的旧 csproj 仍然无法工作,请考虑 <TargetFrameworkProfile>指示。它存在于您的新工作 csproj 中吗?考虑删除它。

关于.net - NuGetPackageImportStamp 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24049961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com