Ben*_*ter 65 visual-studio nuget
有没有人知道如何让Visual Studio为每个解决方案而不是在所有解决方案中应用NuGet包源配置?我一直有版本问题因为我在多个项目上工作,每个项目都有自己的私有NuGet存储库.在***中记住哪个NuGet repo属于哪个项目并返回并将正确的项目应用于正确的项目是一件痛苦的事.
Ben*_*ter 116
TLDR:是的
NuGet使用从Windows用户配置文件级别的NuGet.config开始的包源的分层应用程序,然后从包含解决方案的文件路径的根目录开始应用越来越多的细粒度配置,最后以包含您的解决方案的目录结束解决方案文件
所以这就是我设法弄清楚的 - 礼貌的一个有用的Twitterer指向我这个文件:
https://docs.nuget.org/consume/nuget-config-file
在Visual Studio的Tools > NuGet Package Manager > Package Manager Settings: Package Sources选项中编辑NuGet包源时,它会默认将这些更改应用于%APPDATA%\NuGet目录中的NuGet.config文件.要在每个解决方案(或每组解决方案)的基础上覆盖这些设置,您需要在解决方案或解决方案的路径中的某处添加策略性放置的NuGet.config文件.
如果您阅读NuGet文档,所有内容都将变得清晰,我在下面提供的解决方案将很快允许您为单个Visual Studio解决方案指定配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<!-- Ditch all the Global NuGet package sources we only want a
single private NuGet repo for this project -->
<clear />
<!-- Add the private NuGet package source for this solution -->
<add key="My Private NuGet Server" value="http://myprivatenuget.com:8080/nuget" />
</packageSources>
<disabledPackageSources>
<!-- Add any package sources to ignore here using the same keys as
defined in the packageSources list above-->
<!--<add key="nuget.org" value="true" />-->
<add key="Microsoft and .NET" value="true" />
</disabledPackageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)
如果你想配置适用于多种解决方案,确保您的解决方案文件夹都包含一个共同的目录中,并把NuGet.config了相关的共同点目录这些解决方案包的来源,以确保任何解决方案文件夹项目是AREN "T使用这些包源不包含在该文件夹中常见.
我想补充由BenAlabaster提供的优秀答案。我有一些相反的问题:
该公司在全球范围内配置了他们的自定义私有 nuget feed,默认情况下用于所有解决方案,我想使用公共 nuget feed制作一个“原型”应用程序。
有了这个(在该解决方案的目录中),公共 nuget 提要仅可用于我的特定解决方案,同时将公司的提要保留为所有其他解决方案的默认值:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Ditch all eventually upwards configured (private) feeds from an (enterprise) environment -->
<clear />
<!-- Make sure we use the public nuget -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<disabledPackageSources>
<!-- Ditch all eventually upwards configured (private) feeds from an (enterprise) environment -->
<clear />
</disabledPackageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)
关键是清除所有向上禁用的提要,因为他们故意禁用了 %APPDATA%\NuGet 中 NuGet.config 中的公共提要。
| 归档时间: |
|
| 查看次数: |
22230 次 |
| 最近记录: |