繁体   English   中英

Nuget软件包未还原

[英]Nuget packages are not restored

我从Gitub克隆了项目。 我的解决方案有6个项目,每个项目都有packages.config文件(其中列出了软件包及其版本),但是这些软件包没有还原。

我已经尝试还原nuget软件包的方法:

  1. 在Visual Studio中: Tools -> Options -> Nuget Package Manger -> General并选中两个选项。
  2. web.config文件中编写以下代码:

<packageRestore> <!-- The 'enabled' key is True when the "Allow NuGet to download missing packages" checkbox is set. Clearing the box sets this to False, disabling command-line, automatic, and MSBuild-Integrated restore. --> <add key="enabled" value="True" /> </packageRestore>

这将还原该项目的软件包,但其他项目没有web.config文件。

  1. %AppData%\\NuGet\\NuGet.Config添加了以下代码:

<configuration> <packageRestore> <!-- The 'automatic' key is set to True when the "Automatically check for missing packages during build in Visual Studio" checkbox is set. Clearing the box sets this to False and disables automatic restore. --> <add key="automatic" value="True" /> </packageRestore> </configuration> <configuration> <packageRestore> <!-- The 'automatic' key is set to True when the "Automatically check for missing packages during build in Visual Studio" checkbox is set. Clearing the box sets this to False and disables automatic restore. --> <add key="automatic" value="True" /> </packageRestore> </configuration>

  1. 在程序包管理器控制台中运行以下命令: Update-Package –reinstall对于所有程序包都这样说:

Package 'Abp.2.1.2' already exists in project 'TempABP5.Migrator' Successfully installed 'Abp 2.1.2' to TempABP5.Migrator

  1. 在您的.sln文件旁边创建了一个NuGet.Config文件,其中包含:

    <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> <add key="aspnetwebstacknightlyrelease" value="https://www.myget.org/f/aspnetwebstacknightlyrelease/" /> </packageSources> </configuration>

来源

  1. 通过从.csproj文件中删除以下代码进行测试:

<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'))" /> </Target> <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'))" /> </Target>

但是我仍然无法还原软件包,并且项目无法构建。 如何恢复丢失的软件包?

更新:

下图包含项目和错误的屏幕截图: 在此处输入图片说明

我删除了bin / obj文件夹中的所有数据,然后清除解决方案,然后构建但出现相同的错误。

然后,我再次运行命令Update-Package –reinstall以确保软件包已经存在,结果是:

安装失败。 正在回滚...项目中不存在程序包“ A”。 程序包“ A”已存在于该文件夹中。

那是因为git版本控制下的“ Packages”文件夹。 您应该使用.gitignore文件使Git忽略packages文件夹的内容。

有关详细信息,您可以参考源代码控制系统中省略NuGet软件包

希望这可以帮到你。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM