英文:
NuGet and Package Sources
问题
I'm looking to see if there's a way to swap the source for a NuGet feed based on the selected project configuration (Debug / Release), I have tried various things with nuget.config and nothing seems to work.
For example something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configurations>
<Debug>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="SomeRepo" value="C:\LocalRepo"/>
</packageSources>
</Debug>
<Release>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="SomeRepo" value="https://live.somerepo/v3/index.json"/>
</packageSources>
</Release>
</configurations>
</configuration>
The reason I'm looking to do this is because when developing locally I have a shared component which kicks out a nuget package to a local folder which is then referenced by this project. On the build server (Azure DevOps) this isn't the case, there is a pipeline / artifacts feed which has a "Release" version of the component I want the project to reference when being built. Hopefully this makes sense, the reason I don't want to reference the release version of the nuget package locally is that I may need to add / change the package and build it locally for speed, instead of having to commit the change, create a pull request, get it reviewed, wait for a build ....
If anyone has any suggestions or is able to help I would really appreciate it.
Thanks in advance
英文:
I'm looking to see if there's a way to swap the source for a NuGet feed based on the selected project configuration (Debug / Release), I have tried various things with nuget.config and nothing seems to work.
For example something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configurations>
<Debug>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="SomeRepo" value="C:\LocalRepo"/>
</packageSources>
</Debug>
<Release>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="SomeRepo" value="https://live.somerepo/v3/index.json"/>
</packageSources>
</Release>
</configurations>
</configuration>
The reason I'm looking to do this is because when developing locally I have a shared component which kicks out a nuget package to a local folder which is then referenced by this project. On the build server (Azure DevOps) this isn't the case, there is a pipeline / artifacts feed which has a "Release" version of the component I want the project to reference when being built. Hopefully this makes sense, the reason I don't want to reference the release version of the nuget package locally is that I may need to add / change the package and build it locally for speed, instead of having to commit the change, create a pull request, get it reviewed, wait for a build ....
If anyone has any suggestions or is able to help I would really appreciate it.
Thanks in advance
答案1
得分: 2
代码部分不需要翻译,以下是翻译的内容:
最简单的方法是在构建时替换整个 nuget.config 文件(或者使用机器范围的配置文件,但在构建服务器上这绝对不是正确的选择)。
我理解在开发过程中希望使用本地包。如果本地包出现了尚未经过拉取请求/审查/构建流程的更改,那么在能够在构建服务器上构建代码之前,您很可能需要等待该更改合并,因此如果您正在进行持续构建,您可能无法在包的更改合并之前推送您的更改,而不会导致构建失败。
英文:
The easiest way to do this is to swap out the entire nuget.config file (or to use a machine-wide config file, but on a build server that is definitely the wrong idea) when you are building.
I understand wanting to use the local package while developing it. If the local package ends up having a change that has not gone through the pull request/review/build process, you are likely to end up needing to wait for that change to be merged in before you can build the code on the build server anyway, so if you are doing continuous builds you may up being unable to push your changes before the package has had its changes merged without suffering a failed build.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论