对于我的大多数项目,我有以下约定:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
/Moq
moq.dll
license.txt
/Yui-Compressor
yui.compressor.dll
/tools
/ILMerge
ilmerge.exe
您会注意到,我没有在源文件夹中保留外部库。我对使用NuGet也很感兴趣,但不希望在源文件夹内使用这些外部库。NuGet是否有一个设置来改变所有包加载到的目录?
为了改变项目的路径使用PackageReference而不是包。配置你需要使用globalPackagesFolder
从https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
globalPackagesFolder (projects using PackageReference only)
The location of the default global packages folder. The default is
%userprofile%.nuget\packages (Windows) or ~/.nuget/packages
(Mac/Linux). A relative path can be used in project-specific
nuget.config files. This setting is overridden by the NUGET_PACKAGES
environment variable, which takes precedence.
repositoryPath (packages.config only)
The location in which to install NuGet packages instead of the default $(Solutiondir)/packages
folder. A relative path can be used in project-specific nuget.config
files. This setting is overridden by the NUGET_PACKAGES environment
variable, which takes precedence.
<config>
<add key="globalPackagesFolder" value="c:\packageReferences" />
<add key="repositoryPath" value="c:\packagesConfig" />
</config>
我放了Nuget。配置旁边的解决方案文件,它工作。
如果您使用的是Visual Studio 2019和NuGet版本4(或更高版本),您可以通过编辑NuGet来更改路径。配置文件。
NuGet。配置文件在“C:\Users%USER_NAME%\AppData\Roaming\NuGet”目录下
在配置文件中增加“globalPackagesFolder”和“repositoryPath”键。设置您想要的值。
这里有一个例子
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="E:\.packages" />
<add key="repositoryPath" value="E:\.nuget" />
</config>
</configuration>
为了改变项目的路径使用PackageReference而不是包。配置你需要使用globalPackagesFolder
从https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
globalPackagesFolder (projects using PackageReference only)
The location of the default global packages folder. The default is
%userprofile%.nuget\packages (Windows) or ~/.nuget/packages
(Mac/Linux). A relative path can be used in project-specific
nuget.config files. This setting is overridden by the NUGET_PACKAGES
environment variable, which takes precedence.
repositoryPath (packages.config only)
The location in which to install NuGet packages instead of the default $(Solutiondir)/packages
folder. A relative path can be used in project-specific nuget.config
files. This setting is overridden by the NUGET_PACKAGES environment
variable, which takes precedence.
<config>
<add key="globalPackagesFolder" value="c:\packageReferences" />
<add key="repositoryPath" value="c:\packagesConfig" />
</config>
我放了Nuget。配置旁边的解决方案文件,它工作。