3

How to use a different nuget sources/feeds for Debug configuration and Release configuration?

USE CASE / CONTEXT

A company publishes Debug and Release binaries for the same source code to configuration-specific nuget feeds, and I need to use these internal nugets as dependency for another 2 separate configuration-specific builds. I intend to use this nuget dependency system only with C# projects.

My first idea was to declare configuration-specific nuget sources in the nuget.config file, but I failed doing so.

It is also quite complicated for me to modify every project file on every single branch to accomplish this challenge, since there are thousands of projects organized ('disorganized') into several directories in the company's repository.

Are there also any good suggestions on how to exactly deal with this real-life problem?

1
  • You can replace sources in nuget.config in your release build pipeline (assuming you have one, or have a build script that produces "release" build that would do the replacement) and have "debug" sources for consumption by developers by default in your source control. However, having the with the same ids and versions to have different content depending on the source sounds like recipe for trouble. Commented May 16 at 21:29

1 Answer 1

1

Limitation: doesn't work in IDE builds

You can use the property RestoreConfigFile in a Directory.Build.targets file (or in the project files). Directory.Build.props is evaluated before the Configuration property is available.

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
  <RestoreConfigFile>$(MSBuildThisFileDirectory)\ReleaseNuGet.config</RestoreConfigFile>
</PropertyGroup>

Alternatively, you can also set the property by passing it as a command line argument to msbuild or dotnet:
/p:RestoreConfigFile=".\ReleaseNuGet.config"


Source: https://github.com/NuGet/Home/issues/5843

Sign up to request clarification or add additional context in comments.

2 Comments

Would that work with Directory.props? I'm not sure if the evaluation of this property happens before or after the Directory.props resolution. The company has thousands of projects in several branches. I'll give this a try and provide feedback later.
If it doesn't, put it in a Directory.Build.targets file, that should be evaluated late enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.