Tomas Jansson
Tomas Jansson

Reputation: 23472

Is there a way to run nuget pack on a project file and get the dependencies automatically?

Let say I have a project that contains a packages.config file. Now when I run nuget pack myproj.csproj in the same folder as the packages.config that belongs to the project I expect nuget to include the dependencies, but that wasn't the case. Is it possible to make it so somehow? Or do I have to create a nuspec file to get dependencies working?

Upvotes: 2

Views: 3191

Answers (3)

Esen
Esen

Reputation: 973

Add this reference CreateNewNuGetPackageFromProjectAfterEachBuild to your project, build your project and you will get the nuget package of your project under bin folder.

https://www.nuget.org/packages/CreateNewNuGetPackageFromProjectAfterEachBuild/

No need to worry about generating nuspec and packaging all necessary dependencies. It takes care of those

Upvotes: 0

Xavier Decoster
Xavier Decoster

Reputation: 14810

As far as I know, the latest version of the NuGet vsix supports this out-of-the-box. If you enable package restore (to get the .nuget folder and msbuild scripts etc), you can add the following MSBuild property to your project file (edit the csproj file):

<BuildPackage>true</BuildPackage>

Now, whenever you build your project, a .nupkg file will be created in your project $(OutDir) whether you have a .nuspec file for the project or not. It will have all dependencies it found in your project's packages.config file.

However, if you do have a .nuspec file in your project folder called {projectname}.nuspec (replace {projectname} with the project filename minus its extension), you'll be able to add additional metadata and contents which can not be derived automatically just by looking at your project. Information on creating such file can be found here.

Upvotes: 3

Related Questions