[英]Nuget packages are not restored
我從Gitub克隆了項目。 我的解決方案有6個項目,每個項目都有packages.config文件(其中列出了軟件包及其版本),但是這些軟件包沒有還原。
我已經嘗試還原nuget軟件包的方法:
Tools -> Options -> Nuget Package Manger -> General
並選中兩個選項。 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文件。
%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>
( 源 )
Update-Package –reinstall
對於所有程序包都這樣說: Package 'Abp.2.1.2' already exists in project 'TempABP5.Migrator' Successfully installed 'Abp 2.1.2' to TempABP5.Migrator
在您的.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>
( 來源 )
.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.