Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug and release nuget packages local repository

We are experimenting with nuget for our visual studio projects. However, we only (or at least mainly) use nuget for our own external references, and we store them in a local repository (network share). What I would like to know is how to handle the whole debug/release situation.

Concrete (simplified) situation:

We have a main project that has references to two shared components that we developed ourselves. These shared components are also used in other products of our company

When we build the main project (azure pipelines), we build the debug and release versions of the project. However, we can only specify a single nuget package for each external reference.

What we want to accomplish to to use the debug version of the shared components during the debug build, and the release version during the release build. However, these are (as far as I know) actually different packages.

What is the way of tackeling this issue? Is there, for instance, a way to include both the release and debug versions in a single nuget package? Is it possible to have to different nuget configurations for different build configuration settings?

I've found Best practices with Nuget: Debug or Release?, however this topic doesn't really address my issue. This thread is more a discussion about whether to publish debug or release versions to a remote server. We want to publish both and use both in a private repository. We have no intention of sharing our libraries with the rest of the world.

like image 949
PaulVrugt Avatar asked Mar 17 '16 07:03

PaulVrugt


People also ask

How do I create a NuGet repository in Visual Studio 2019?

Let's configure Visual Studio to configure this new repository. Navigate to Tools | NuGet Package Manager | Package Manager Settings | Package Sources, Right-click on the root project in Solution Explorer and select Manage NuGet Packages to open the NuGet Package Manager.

Is it possible to create a release NuGet package with debug symbols?

Ideally, what would happen then is that nuget pack SomePackage -Symbols against a release version would create a release nuget package, but a debug symbols package. And the VS plugin would be updated to be smart enough to see the association and pull in the Debug assemblies when running in a debugger and load those instead.

Is there a way to debug DLLs in NuGet?

IF nuget had a way to load debug dlls in debug mode and release dlls in release mode (from nuget packages), this would be the ultimate. Until then we are stuck with Nuget package switcher I concur, this would be a nice product enhancement.

How to add NuGet local to a Visual Studio project?

Next you will need to add NuGet.Local to the package sources in Visual Studio: Create a new C# class library project, right-click on the project and select Manage NuGet Packages. Select NuGet.Local in the list of Online sources and install your package. As you can see from the screenshot below MyApp package has a dependency on Newtonsoft.Json:


1 Answers

A NuGet package will normally hold just a single set of assemblies for a particular target framework. It is not really designed to ship a debug and release version since you are publishing the NuGet package to be consumed by other users. Normally you do not publish a debug and a separate release version of your application to end users.

You may be able to workaround this by using a custom MSBuild .targets file in the NuGet package that has its own references and configuration information. You can use this .targets file as an extension to your project. It will be imported so you can define the references as you need based on the configurations defined in your project. It is not ideal but it should work.

like image 194
Matt Ward Avatar answered Oct 11 '22 14:10

Matt Ward