Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

visual studio - Build NuGet Package automatically including referenced dependencies

I want to run a local/internal NuGet repository. I think I've figured out how to "reuse" existing NuGet packages by including them in a dummy project using NuGet and scanning the package file to grab my locally-cached .nupkg files, but...

How do you create a nuget package (.nupkg) from a project, automatically including all dll dependencies and not just those grabbed via NuGet?

Specifically:

  1. Create a solution
  2. Add a new Project
  3. Add references to various .dll files/other projects <-- this is the missing part
  4. Add NuGet packages via package manager / cmdline / whatever
  5. something automatically creates the .nupkg

From what I've found, you're supposed to do things like

  • manually edit your .csproj file to add <BuildPackage>true</BuildPackage> to include dependencies
  • manually create a .nuspec file and manually list your dependencies (similar ?)
  • manually run nuget pack on your .nuspec file

But everything is manual, which is stupid. Even the semi-automatic solutions are still awkward or half-manual:

I'll settle for something that automatically creates a .nuspec manifest from project references. Then theoretically that + the nuget build-event can be rolled up into a build-project/nuget package, which is what I really want to see.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your point #3 (Add references to various .dll files/other projects <-- this is the missing part) really contains two different issues: (1) add references to various dll files, and (2) add references to other projects in the same solution.

Number (2) here has gotten some added support as of NuGet 2.5. You can add an option to include references to other projects in the same solution when creating a NuGet package for a project:

nuget pack projectfile.csproj -IncludeReferencedProjects

If projectfile.csproj references any other projects in your solution that also is exposed as NuGet packages, these projects' NuGet packages will be added as dependencies. If it references projects in your solution that doesn't expose themselves as NuGet packages, their dlls will be included in this NuGet package.

As for (1), if you find yourself often adding dlls to your projects that aren't available as NuGet packages, you could just create your own (internal) NuGet packages with these files. If you then add these dlls as a NuGet package instead of the files directly, this NuGet package will be a dependency in your project's NuGet package.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...