Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory structure for a NuGet published github hosted project

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?

like image 428
Remus Rusanu Avatar asked Nov 07 '12 15:11

Remus Rusanu


People also ask

How do I create a NuGet package in Visual Studio?

To create a NuGet package from your project, follow these steps: Select Build > Configuration Manager, and then set the Active solution configuration to Release. Select the AppLogger project in Solution Explorer, and then select Build > Pack. Visual Studio builds the project and creates the .

What is a NuGet package?

Put simply, a NuGet package is a single ZIP file with the . nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number.


1 Answers

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

like image 103
Filip De Vos Avatar answered Sep 30 '22 18:09

Filip De Vos