对于我的大多数项目,我有以下约定:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
/Moq
moq.dll
license.txt
/Yui-Compressor
yui.compressor.dll
/tools
/ILMerge
ilmerge.exe
您会注意到,我没有在源文件夹中保留外部库。我对使用NuGet也很感兴趣,但不希望在源文件夹内使用这些外部库。NuGet是否有一个设置来改变所有包加载到的目录?
这些答案都不适合我(Nuget 2.8.6),因为缺少一些提示,我会尝试在这里添加它们,因为它可能对其他人有用。
阅读以下资料后:
https://docs.nuget.org/consume/NuGet-Config-Settings
https://github.com/NuGet/Home/issues/1346
看来
To make working Install-Package properly with different
repositoryPath you need to use forward slashes, it's because they are using Uri object to parse location.
Without $ on the begining it was still ignoring my settings.
NuGet caches config file, so after modifications you need to reload solution/VS.
I had also strange issue while using command of NuGet.exe to set this option, as it modified my global NuGet.exe under AppData\Roaming\NuGet and started to restore packages there (Since that file has higher priority, just guessing).
如。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositorypath" value="$/../../../Common/packages" />
</config>
</configuration>
你也可以使用NuGet命令来确保语法是正确的,就像这样:
NuGet.exe config -Set repositoryPath=$/../../../Common/packages -ConfigFile NuGet.Config
VS 2017更新:
看起来人们在Nuget团队终于开始使用Nuget自己,帮助他们找到和修复几个重要的东西。所以现在(如果我没有弄错的话,因为还没有迁移到VS 2017)下面的内容不再需要了。您应该能够将“repositoryPath”设置为本地文件夹,并且它将工作。甚至可以将其保留为默认恢复位置,从解决方案文件夹移到机器级。我还是没有自己测试
VS 2015及更早
只是给其他答案一个提示(特别是这个):
NuGet包文件夹的位置可以通过配置来更改,但是VisualStudio仍然相对地引用此文件夹中的程序集:
<HintPath>..\..\..\..\..\..\SomeAssembly\lib\net45\SomeAssembly.dll</HintPath>
为了解决这个问题(直到有更好的解决方案),我使用subst命令创建了一个指向Packages文件夹新位置的虚拟驱动器:
subst N: C:\Development\NuGet\Packages
现在当添加一个新的NuGet包时,项目引用使用它的绝对位置:
<HintPath>N:\SomeAssembly\lib\net45\SomeAssembly.dll</HintPath>
注意:
这样的虚拟驱动器将在重新启动后删除,因此请确保您处理了它
不要忘记替换项目文件中现有的引用。
2.1版本说明中提出的解决方案不能开箱即用。他们忘了提到代码:
internal string ResolveInstallPath()
{
if (!string.IsNullOrEmpty(this.OutputDirectory))
{
return this.OutputDirectory;
}
ISettings settings = this._configSettings;
...
}
这阻碍了它的工作。要解决这个问题,你需要修改你的NuGet。然后删除“OutputDirectory”参数:
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch)</RestoreCommand>
所以现在,如果你在NuGet中添加'repositoryPath'配置。Config(参见发布说明中关于放置配置文件的有效位置的描述),它将把所有包恢复到单个位置,但是…您的.csproj仍然包含以相对路径编写的程序集提示…
我仍然不明白为什么他们走了艰难的道路,而不是改变PackageManager,这样它就会添加相对于PackagesDir的提示路径。这就是我手动在本地(在我的桌面上)和构建代理上拥有不同包位置的方法。
<Reference Include="Autofac.Configuration, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>$(PackagesDir)\Autofac.2.6.3.862\lib\NET40\Autofac.Configuration.dll</HintPath>
</Reference>
如果您使用的是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>
这些答案都不适合我(Nuget 2.8.6),因为缺少一些提示,我会尝试在这里添加它们,因为它可能对其他人有用。
阅读以下资料后:
https://docs.nuget.org/consume/NuGet-Config-Settings
https://github.com/NuGet/Home/issues/1346
看来
To make working Install-Package properly with different
repositoryPath you need to use forward slashes, it's because they are using Uri object to parse location.
Without $ on the begining it was still ignoring my settings.
NuGet caches config file, so after modifications you need to reload solution/VS.
I had also strange issue while using command of NuGet.exe to set this option, as it modified my global NuGet.exe under AppData\Roaming\NuGet and started to restore packages there (Since that file has higher priority, just guessing).
如。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositorypath" value="$/../../../Common/packages" />
</config>
</configuration>
你也可以使用NuGet命令来确保语法是正确的,就像这样:
NuGet.exe config -Set repositoryPath=$/../../../Common/packages -ConfigFile NuGet.Config