2

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?

Tomas Jansson
  • 20,796
  • 9
  • 68
  • 121

3 Answers3

3

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.

Xavier Decoster
  • 14,182
  • 4
  • 33
  • 45
  • Not exactly what I asked but good feedback. Is it possible to do it through command line as so I don't have to update the csproj file and can let my build server handle it? – Tomas Jansson Mar 15 '12 at 08:55
  • Sorry, didn't notice you're question was asked targeting nuget.exe outside of the context of Visual Studio. Don't think cmdline has such option so you can avoid modifying the csproj file. However, the solution I proposed can be handled by the build server as it consists out of an msbuild + nuget.exe approach. (don't forget to commit the .nuget folder) – Xavier Decoster Mar 15 '12 at 09:39
  • @XavierDecoster And what if I don't want this automatic behavior of adding dependencies, but rather I'd like NuGet to only include those I explicitly specified in the `` tag of the nuspec file?? Is this possible?? – Juri Oct 31 '12 at 08:50
  • @Juri AFAIK that's only possible if you target the nuspec file instead of the csproj file. But why would you remove a dependency from the package you produce if the project depends on it? – Xavier Decoster Oct 31 '12 at 12:18
  • When making use of .Net's lazy loading feature of dependencies (too long story for this comment here). It's for sure not best a best practice ;) but often we have to be pragmatic. But thx, I'll give it a try – Juri Oct 31 '12 at 15:35
  • It's for situations where you want to go into the details of .Net assembly loading, making use of this dark "black magic" ;) like http://goo.gl/mxorR – Juri Nov 06 '12 at 14:50
  • Are these dependencies only NuGet dependencies, or are we talking about project references too? I'm trying to figure out what to expect. – drzaus Apr 23 '13 at 15:05
1

Is this you are after? https://stackoverflow.com/a/16310138/3285954

IncludeReferencedProjects

https://docs.nuget.org/consume/command-line-reference#pack-command-options

Community
  • 1
  • 1
user3285954
  • 4,025
  • 2
  • 23
  • 19
0

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

Esen
  • 907
  • 1
  • 18
  • 44