![](/img/trans.png)
[英]Visual Studio Professional 2012 error: This project references NuGet package(s) that are missing in ASP.NET MVC project
[英]How to fix a missing NuGet package error?
我在 Git 下的 Visual Studio 中有一個 C++ 控制台應用程序,其中我有一個名為LibrarySubmoduleSolution
的子模塊 static 庫。 這個LibrarySubmoduleSolution
使用Windows實現庫NuGet package。
在我的VCPPConsoleApplicationSolution
主解決方案中下載 Git 子模塊並在解決方案中恢復 NuGet 包后,我收到以下錯誤:
嚴重性代碼 描述 項目文件行
抑制 State 錯誤此項目引用此計算機上缺少的 NuGet 包。 使用 NuGet Package 恢復下載它們。 有關詳細信息,請參閱http://go.microsoft.com/fwlink/?LinkID=322105 。 缺少的文件是..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets。 庫子模塊解決方案
D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution.vcxproj 166 嚴重性代碼描述項目文件行
抑制 State 錯誤 C1083 無法打開包含文件:'wil/resource.h':沒有這樣的文件或目錄
VCPPConsoleApplicationSolution
D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\SomeClass.h 3
我在 Google 和 Stackoverflow 上搜索了答案,甚至在我編輯了LibrarySubmoduleSolution.vcxproj
文件並將包文件夾從..\packages
更改為$(SolutionDir)\packages
之后:
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
</Target>
我仍然無法構建錯誤:
嚴重性代碼 描述 項目文件行抑制 State 錯誤 C1083 無法打開包含文件:'wil/resource.h':沒有此類文件或目錄 VCPPConsoleApplicationSolution D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\SomeClass.h 3
只有在我的主控制台應用程序項目中安裝 Windows 實現庫 NuGet package 之后,它才開始構建而沒有錯誤。
以下是快速重現錯誤的主要和子模塊解決方案: https://github.com/KulaGGin/VCPPConsoleApplicationSolution https://github.com/KulaGGin/LibrarySubmoduleSolution
如何修復缺少的 NuGet package 錯誤?
我從 github 下載了您的項目,並遇到了與您描述的相同的問題。
主要問題是您的 nuget 軟件包已損壞,或者您的項目引用 Nuget package 存在問題。
請按照這些步驟操作,我通過它們解決了問題。
建議
1) 清除所有 nuget 緩存或僅刪除C:\Users\xxx(current user name)\.nuget\packages
下的所有文件
2)關閉VS Instance,刪除解決方案文件夾下的.vs
隱藏文件夾和任何output文件夾,如x64
文件夾
3) run the command update-package -reinstall
under Tools --> Nuget Package Manager --> Package Manager Console to reinstall that package in your project.
然后,錯誤就會消失。 我遵循這些並最終得到它。
更新 1
============================
很抱歉沒有仔細觀察您的問題。 問題出在xxx.vcxproj
文件中。
問題在於:
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
我想知道你為什么要使用$(SolutionDir)
而不是..
。
在您的問題中, $(SolutionDir)\packages
表示xxx(SolutionName)\\packages
。
$(SolutonDir)
表示xxxx\LibrarySubmoduleSolution\
並且它已經包含\
。
解決方案
請刪除$(SolutionDir)
和packages
之間的\
並更改為:
$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets
in both of the xml nodes.
===============================
更新 2
此外,如果你的主項目VCPPConsoleApplicationSolution
引用了LibrarySubmoduleSolution
並使用了它的文件,你也應該在主項目中包含這樣的庫路徑,否則在主項目VCPPConsoleApplicationSolution
中找不到resource.h
。
實際上,當您在主項目VCPPConsoleApplicationSolution
中從LibrarySubmoduleSolution
中引用someclass.h
時, someclass.h
文件將被復制到VCPPConsoleApplicationSolution
中,在這種環境下,您在LibrarySubmoduleSolution
中安裝它時並沒有這樣的庫wil/resource.h
。 在主項目中,沒有安裝nuget包(自動包含resource.h
所在的include路徑),所以會報錯。
作為一個建議,
您可以右鍵單擊VCPPConsoleApplicationSolution
屬性 - > VC++ Dirctories
- > 添加xxxx\VCPPConsoleApplicationSolution\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\include
到Include Directories
。
或者在主項目中安裝 nuget package 以自動包含庫路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.