1

I'm moving over a project to make it into a nuget package. The project has preprocessor directives in it to check which custom build configuration the developer is in. If they are in Build config A then it pulls A service settings, if they are in B, then it pulls B's settings. The problem is when I package this service up and the nuget package is being used in a separate process with the same build configuration it doesn't respect the devs build configuration choice because the nuget has been compiled with whatever setting it was built in. We have set it up into 3 dlls in a single nuget package.

Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?

kuskmen
  • 3,648
  • 4
  • 27
  • 54
Dakota Kincer
  • 448
  • 3
  • 16
  • If these configurations are so different, producing 3 separate nuget packages with different IDs may also be an option. Or externalise the configuration (=> consuming project needs to set up the library) etc. – Martin Ullrich Aug 11 '17 at 13:44
  • 1
    @Dakota Kincer, Any update for this issue? Could you get useful information from the answer? If not, please let me know for free. – Leo Liu Aug 15 '17 at 02:58
  • Ive marked your answer as the answer. We can't currently move our project to nuget and have opted leave it as a project reference for now. It would be nice in the future to have some way to switch between build configurations. We are currently using that as a switch to point to production and staging environments. – Dakota Kincer Aug 15 '17 at 11:28

1 Answers1

2

Is there a way to choose which nuget dll it uses based on the custom build configuration without modifying the csproj code?

This is not supported as far as I am aware with the NuGet. You can only have one NuGet package with a specific build configurations in a single project's file. Moreover, NuGet now only supports multiple .NET framework versions, not supported multiple configurations.

You can have different NuGet packages if you have different build configurations. This project is specific use by library authors who have platform specific projects that need different NuGet packages.

Besides, It may be simpler to not use NuGet to add the assemblies to your project. Just use NuGet to pack the package with multiple dlls file, then directly reference the assemblies you need with conditions.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    In the answer above, you say "different NuGet packages if you have different build configurations." how do you do that? – Peter May 04 '18 at 12:58