Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to temporarily replace a NuGet reference with a local build

Tags:

c#

nuget

I'm working on a C# project using Visual Studio 2015, with NuGet for package management. For one reference, I'd like to temporarily use a local build while I'm iterating on a fix, rather than the released version. What's the best way to accomplish this?

If I were using an SVN external, I'd drop the new locally built copies into the external reference's folder, and be set. Other package management software (like CocoaPods) would allow me to point to a local directory to resolve the reference. With NuGet, it doesn't look like there's any mechanism for this.

When I try dropping my new DLL over the package reference inside the packages folder, I get inconsistent behavior in Visual Studio. My build will fail with hundreds of errors, most of which go away from the Error List quickly. I'm ultimately left with a warning telling me it could not resolve the reference to the assembly I'm trying to replace (though the properties of the reference do indicate it's finding my new version).

like image 680
Dov Avatar asked Sep 09 '15 14:09

Dov


People also ask

How do I manually add a NuGet to a project?

Menu Tools → Options → Package Manager Click OK. Drop your NuGet package files in that folder. Go to your Project in Solution Explorer, right click and select "Manage NuGet Packages". Select your new package source.

Where NuGet packages are stored locally?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder. When using the packages.


1 Answers

I found the following workaround useful for me:

First I disable "NuGet Package Restore" from the context menu of the Solution.

After that I go to the %HOMEPATH%\.nuget\packages folder, and search for the package I want to replace. From this package I take the version number, and use this exact version number to build the dll I want to exchange.

After that I can exchange the dll in the packages folder with this newly built dll. Building the project now uses this new dll.

After having this set up once, I can easily build new dlls, and copy them to the packages folder.

like image 64
Matthias Avatar answered Sep 21 '22 21:09

Matthias