I want to place the NuGet package in the absolute path D:\vc_packages
for unified management, instead of each project having its own packages
directory, so I modified the NuGet.Config
in the C:\Users\h'y\AppData\Roaming\NuGet
directory, I have added two settings to the Config file:
<config><add key="repositoryPath" value="D:\vc_packages" /><add key="globalPackagesFolder" value="D:\vc_packages" /></config>
After setting it up, my project does not search for NuGet packages in its own packages
directory, but instead looks for Nuget packages in D:\vc_packages
. However, there is a problem with this, which is that the.vcxproj
file in the project uses a relative path to find the D:\vc_packages
directory, as follows:
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /><ImportGroup Label="ExtensionTargets"><Import Project="..\..\..\..\vc_packages\glfw.3.4.0\build\native\glfw.targets" Condition="Exists('..\..\..\..\vc_packages\glfw.3.4.0\build\native\glfw.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('..\..\..\..\vc_packages\glfw.3.4.0\build\native\glfw.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\vc_packages\glfw.3.4.0\build\native\glfw.targets'))" /></Target>
When my project is placed in different folders, there may be a situation where I cannot find the NuGet package. In this case, I need to manually set the content in .vcxproj
, change ..\..\..\..
to D:
. How can I avoid this problem? The absolute path D:\ vc_packages
is used directly in the .vcxproj
file?
I use Windows 10 system, VS2022
How do I need to modify it so that when adding a new NuGet package, I can directly use the absolute path D:\vc_packages
in the .vcxproj
file?