NuGet和包源

huangapple go评论50阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;configuration&gt;		
	&lt;configurations&gt;
        &lt;Debug&gt;
			&lt;packageSources&gt;
                &lt;add key=&quot;nuget.org&quot; value=&quot;https://api.nuget.org/v3/index.json&quot; protocolVersion=&quot;3&quot; /&gt;
                &lt;add key=&quot;SomeRepo&quot; value=&quot;C:\LocalRepo&quot;/&gt;
            &lt;/packageSources&gt;
		&lt;/Debug&gt;
        &lt;Release&gt;
            &lt;packageSources&gt;		
			    &lt;add key=&quot;nuget.org&quot; value=&quot;https://api.nuget.org/v3/index.json&quot; protocolVersion=&quot;3&quot; /&gt;
                &lt;add key=&quot;SomeRepo&quot; value=&quot;https://live.somerepo/v3/index.json&quot;/&gt;
            &lt;/packageSources&gt;
		&lt;/Release&gt;
    &lt;/configurations&gt;
&lt;/configuration&gt;

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.

huangapple
  • 本文由 发表于 2023年2月14日 00:13:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438470.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定