.nu get文件夹为什么有解决方案呢?

问题描述 投票:3回答:3

在工作中我们不使用nuget,即使在我的个人项目中我使用它,我也不明白为什么我下载的许多解决方案都有它,通常有3个文件

Nuget.config,exe和target。

有人可以解释为什么人们将这个文件夹添加到他们的解决方

谢谢

c# nuget
3个回答
4
投票

在过去的好时光中,该文件夹是NuGet包恢复的关键参与者(NuGet.targets就是证据)。但是由于新的恢复机制到位,只有NuGet.exe才有用。

您可以从NuGet.org阅读更多内容,

https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

更新:

链接的文章已更新并移至Microsoft Docs

如果您仔细阅读上述内容,MSBuild 15还会添加NuGet包恢复支持。


2
投票

从nuget 2.7+开始,不再需要此文件夹,可以安全删除。此外,如果您使用Visual Studio命令行提示符,您应该能够从那里访问nuget.exe,以及在Visual Studio中从包管理器访问。

要在使用nuget 2.6或更早版本的项目中启用自动程序包还原,您可能需要从* .csproj文件的底部手动删除以下内容:

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    <Error Condition="!Exists('..\..\packages\MSBuildTasks.1.5.0.214\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSBuildTasks.1.5.0.214\build\MSBuildTasks.targets'))" />
  </Target>

0
投票

我想补充Lex Li的答案。 .nuget文件夹中的另一个重要文件是nuget.config文件,特别是如果你使用nuget.org以外的其他feed中的nuget包。

假设您已按如下方式配置了另一个包源:

Nuget Package Sources

当您在本地计算机上添加或恢复软件包时,一切都会正常工作,因为nuget知道从哪里获取软件包。当您在持续集成(CI)服务器(例如Visual Studio Team Services)上构建解决方案时,nuget包的还原/安装可能会失败,因为CI服务器不知道从哪里获取来自!

因此,如果您将包源添加到.nuget/nuget.config

Nuget.config with custom package sources

然后,您可以使用配置文件来恢复/安装nuget软件包 - 这就是我在Visual Studio Team Services中的操作方法:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.