12

For a github hosted open sourced C# project which is also available via NuGet, how should one organize the source? Specifically:

  • should the .nuspec file be in the github repository?
  • should the .nuspec file be in the same folder as the .csproj file?
  • how about the NuGet package tree (the /lib, /content stuff), since is generated, should it be in git?

My thinking is that the NuGet part is separate from the github hosting, as in the project source are available but the .nuspec is not, since the publishing in NuGet is not an open source operation per-se. None wants that every fork to build and publish a new NuGet package, so that the open source Foo package ends up in the gallery as 'Rick's Foo' vs. 'John's Foo' vs. 'Alice's Foo' etc.

But on the other hand I do want the github source depot to act as a one-stop repository for the project, if I open my other laptop and enlist from there, I should be able to build/package/push w/o recreating the whole NuGet infrastructure from scratch (ie. only enter my API key, nothing more).

These two requirements are contradicting each other, Did I miss something obvious?

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569

2 Answers2

9

I would do the following:

  • Commit the .nuspec file next to the .csproj file
  • Add a nuget.config file which moves the packages folder a level up.
  • Enable package restore in the solution and do NOT commit the content of the NuGet package repository
  • Create an msbuild file (or whatever build vehicle you like) which has:
    • a "build" target which builds the source and creates the nuget package
    • a "publish" target which pushes the NuGet package to nuget.org and takes your API key as a parameter.

I personally maintain the version number of the nuget package in the .nuspec file and manually update it when I do a "release". This way I can tag the exact release I pushed to the NuGet feed.

With this setup a build in Visual Studio does not produce a NuGet package but all tools are available in the repository to do so.

The Folder Structure looks like this:

   .\Docs\ ==> not in source repo
   .\Packages\ ==> not under source control
   .\Src\ ==> git repo here
   .\Src\MySolution.sln
   .\Src\.gitignore
   .\Src\MuRules.ruleset
   .\Src\build.proj ==> msbuild file to build everything.
   .\Src\MyProject\MyProject.csproj
   .\Src\MyProject\MyProject.nuspec
   .\Src\MyProject\nuget.config
   .\Build\ ==> not under source control
   .\Build\Debug\
   .\Build\Release\
   .\Build\Publish\

Be aware of this bug in the Package Restore feature, it will ignore the packages location you configured. http://nuget.codeplex.com/workitem/1990 ==> This is fixed in Nuget 2.7

Community
  • 1
  • 1
Filip De Vos
  • 11,568
  • 1
  • 48
  • 60
0

On nuget v2.8, I just need to modify .gitignore and add:

packages/

This will exclude the nuget packages folder from committing. When you build the new checked-out source code, the packages would be downloaded and restored. Make sure package restore setting has been enabled but I think it's been enabled by default on v2.8.

null
  • 8,669
  • 16
  • 68
  • 98