I have a C++ console application in Visual Studio under Git, in which I have a submodule static library called LibrarySubmoduleSolution
. This LibrarySubmoduleSolution
uses Windows Implementation Library NuGet package.
After I download Git submodule in my VCPPConsoleApplicationSolution
main solution and restore NuGet packages in the solution, I get these errors:
Severity Code Description Project File Line
Suppression State Error 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 ..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets. LibrarySubmoduleSolution
D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution.vcxproj 166 Severity Code Description Project File Line
Suppression State Error C1083 Cannot open include file: 'wil/resource.h': No such file or directory
VCPPConsoleApplicationSolution
D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\SomeClass.h 3
I searched for answers on Google and here on Stackoverflow and even after I edit my LibrarySubmoduleSolution.vcxproj
file and change packages folder from ..\packages
to $(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>
I still can't build with the error:
Severity Code Description Project File Line Suppression State Error C1083 Cannot open include file: 'wil/resource.h': No such file or directory VCPPConsoleApplicationSolution D:\Projects\Tests\VCPPConsoleApplicationSolution\LibrarySubmoduleSolution\LibrarySubmoduleSolution\SomeClass.h 3
Only after I install Windows Implementation Library NuGet package in my main console application project, it starts to build without errors.
Here is main and submodule solutions to quickly reproduce errors: https://github.com/KulaGGin/VCPPConsoleApplicationSolution https://github.com/KulaGGin/LibrarySubmoduleSolution
How to fix a missing NuGet package error?
I downloaded your project from the github and faced the same issue as you described.
The main issue is that your nuget packages has broken or there is a problem with your project referencing the Nuget package.
Please follow these steps and I solved the issue through them.
Suggestion
1) clean all nuget caches or just delete all files under C:\Users\xxx(current user name)\.nuget\packages
2) close VS Instance, delete .vs
hidden folder under the solution folder and any output folder like x64
folder
3) run the command update-package -reinstall
under Tools-->Nuget Package Manager--> Package Manager Console to reinstall that package in your project.
Then, the error will disappear. I follow these and finally get it.
Update 1
===========================
Sorry for not observing your issue in detail. The problem is in the xxx.vcxproj
file.
The problem is under:
<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')" />
I wonder why you want to use $(SolutionDir)
instead of ..
.
In your issue, $(SolutionDir)\packages
means xxx(SolutionName)\\packages
.
$(SolutonDir)
means xxxx\LibrarySubmoduleSolution\
and it already contains \
.
Solution
Please delete \
between $(SolutionDir)
and packages
and change to this:
$(SolutionDir)packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\build\native\Microsoft.Windows.ImplementationLibrary.targets
in both of the xml nodes.
==============================
Update 2
Besides, if your main project VCPPConsoleApplicationSolution
references LibrarySubmoduleSolution
and uses its file, you should also include such library path in the main project, otherwise, it will not find the resource.h
in the main project VCPPConsoleApplicationSolution
.
Actually, when you reference the someclass.h
from LibrarySubmoduleSolution
in the main project VCPPConsoleApplicationSolution
, the someclass.h
file will be copied into VCPPConsoleApplicationSolution
, in such environment, there is no such library wil/resource.h
while you installed it in LibrarySubmoduleSolution
. In the main project, it did not install that nuget package(to include the include path where exists resource.h
automatically), so the error will occur.
As a suggestion,
you could right-click on VCPPConsoleApplicationSolution
properties--> VC++ Dirctories
--> add xxxx\VCPPConsoleApplicationSolution\packages\Microsoft.Windows.ImplementationLibrary.1.0.200519.2\include
into Include Directories
.
Or install that nuget package in the main project to include the library path automatically.