spottedmahn
spottedmahn

Reputation: 16031

Working with Multiple Nuget Projects in one Solution

I have 2 projects: A & B that I want to publish as NuGet Packages but I don't know how to develop efficiently in Visual Studio.

Solution 1
   Project A
   Project B - references Project A as NuGet reference

When I make a change to Project A that is needed in Project B do I have to publish Project A? Is there a way to get the project reference functionality during development? Maybe Project B shouldn't reference Project A via NuGet?

There must be a good way to handle this situation, no? I've reviewed the NuGet docs but I couldn't find anything. There must be docs/blogs/SO posts to read more about this... I'm struggling to come up w/ the right keywords.

Upvotes: 4

Views: 3125

Answers (4)

Elan Hasson
Elan Hasson

Reputation: 1270

Check out this blog post: https://markheath.net/post/multiple-nuget-single-repo

Basically, dotnet pack handles this for you automatically. You use regular project references when developing.

Upvotes: 4

Leo Liu
Leo Liu

Reputation: 76928

There must be a good way to handle this situation, no?

The best solutions is that the project-to-project reference should be recommend when the referenced project is modified frequently, the nuget reference is more appropriate when share the reference project to others or publish it. Just like NuGet Reference Switcher doing.

For some more detailed info, you can check following thread:

nuget packages in local work

NuGet has many advantages as a package manager for the Microsoft development platform, this does not mean that it is not flawed. Just as you encountered, if the referenced project is modified frequently, we have to rebuild it, build nuget, publish it for each modification. That will bring a lot of boring work. To resolve this disadvantages, the Project-to-project references should be a better way.

The advantage of a project-to-project reference is that it creates a dependency between the projects in the build system. The dependent project will be built if it has changed since the last time the referencing project was built. A file reference does not create a build dependency, so it is possible to build the referencing project without building the dependent project.

Upvotes: 2

Kiliman
Kiliman

Reputation: 20322

You might want to look at this extension: NuGet Reference Switcher for Visual Studio 2017

This allows you to switch between NuGet packages and project references during development.

Upvotes: 3

Weiwei
Weiwei

Reputation: 3776

You could add following Post-build event command to pack your project after building.

"the nuget.exe path\nuget.exe" pack "project path\NuGetPackageLibrary.csproj" -OutputDirectory "Your target path"

When your build successful, the package in target path will be replaced by the latest version.

Upvotes: 1

Related Questions