Go open-source with your .NET project
Have you ever wondered how hard it could be to share your project with the world wide web?
With Visual Studio 2015, GitHub and NuGet you can easily publish the source code and binary library of your project to the open-source community! Of course you can do similar with other IDEs and platforms but those resemble to most popular ones.
Let us see how easily we can do this.
To try this out I am sharing a .NET geometry PCL library with the world, Zw.Geometry. It most not necessarly be very successful, wide-spread or popular but I just wanted to share it as I cannot find something as simple as it and still have some features to be added. So let us give back and provide others with the possiblity to use an existing library to rotate points in a 2D coordinate system without reading all those trigonometry formulars.
First we will require a GitHub account if you do not have already one. I will use GitHub to publish the source code and be able to share it with others and even be able to accept their inputs to my projects (push requests). Next, for those who will purely consume my library, I will require a NuGet account which is a wide-spread package manager for .NET tools and libraries. It is even not limited to Visual Studio as its command line tools are available of others IDEs and Mono too. With the account we can publish packages for others to use.
At this point I already started the small solution which consists of the main project file and a test project with the unit tests. With the Microsoft Git Provider the solution already has a local versioning repository.
So we create a new GitHub remote repository with which we will be able to sync. We should not include a README at this point, we can add it later.
After the creation GitHub shows us the URL to the repository, like https://github.com/ZoolWay/Geometry
In Visual Studio we can now select the Team Explorer, Home, Sync and setup the remote repository in the yellow highlighted Textbox (“Publish to Remote Repository”).
After that we can Sync or Push our commits to the remote repository.
Now you can check out your repository in the webbrowser in GitHub and should be able to see all your source code. You can now add a README and license file those will be downloaded to your local repository the next time you perform a sync. Note: That will not be visible in Visual Studio by default because they are not added to the VS solution file but you can see them in the file system and if you would like manually add them to your repository.
At this step you are ready to go. Find some friends to work on your project. They can checkout (subversion speaking) or more clone (git like) the repository.
When you have a nice library (or other project) most people just would like to use it. They are not interested in cloning the repository and have all the code. A binary and reference will be fine. This is what NuGet provides to the .NET community for quite some time now. The NuGet client is available as Visual Studio integration and command line utility but only the later will help you to pack your binary for the NuGet gallery.
I mostly followed the instructions from the NuGet docs and just encountered minor pitfalls here. Thanks to the extension Open Command Line I can just rightclick my project file and open the VS command prompt in the folder. But by default there is no NuGet command line utility so I downloaded it and put it into the folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools. It is then available in the path when using VS command prompts.
To create a new .nuspec file for your project you can just
After that I included the Zw.Geometry.nuspec into my solution to easily edit it from Visual Studio. Most things can remain unchanged as placeholders are used (which inject information from AssemblyInfo.cs when packing). I added URLs to my project and license and added some tags.
When everything is ready, the unit tests run fine and you do your first release you can run
nuget pack MyProject.csproj -Prop Configuration=Release -Build
Read the docs to get more information about other flags and dependencies to other projects.
The resulting MyProject.126.96.36.199.nupkg can be uploaded using the NuGet webinterface – or you can automate it with an API key and some scripts.
Those are the main steps. Of course there is many things left to really have a successful open source project but I felt a short starter like this would be helpful.
You can find my small sample library online: