簡體   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