CSharp.Mongo.Migrations
Building and Releasing an Open-source Library using .NET & GitHub
Open-source libraries are a major part of developing software, whether consuming them as libraries through a package manager, interacting with other developers, or contributing back to the community, there aren’t many projects or organisations that don’t rely on open-source software.
This article will cover the basics of getting started with library development in .NET and GitHub using the CSharp.Mongo.Migration library as an example.
Setting Up a Repository (with GitHub)
In software development, version control is a must. If you are already familiar with, and use another source control host, consider skipping this section of the article. Sharing, collaboration, and discussion are all large parts of open-source software development. GitHub is a great (and free, for public repositories) tool to manage:
- Code with git
- Documentation through wikis
- Issue tracking and discussion
- Simple kanban style project management
- CI/CD
Creating the Repository
In order to get started with a new GitHub repository you must first sign up for an account (or use an existing one), after which you will be able to create your repository.
Decisions
There are a number of decisions that should be made before getting started on your open-source library:
- Name: this is the user visible name of your repository, and therefore library or project, in .NET this might be your solution name, or root project namespace.
- Open-source licence: This licence will help to protect your project from unfair use, see https://choosealicense.com/ for the basics on selecting a licence.
Givens
There are some assumed settings for a new open-source, .NET repository:
- Visibility: This should be public, otherwise you aren’t really building an open library!
- Readme: All public libraries should have a helpful README.md file, here's an example.
- Gitignore: ‘Visual Studio’ is the default ignore file for .NET projects.
Configuring the Repository
You may wish to enable the following extra features for your repository:
- Wikis: Consider adding a wiki to document your libraries API.
- You may want to restrict editing of the wiki to collaborators only.
- Issues: Allows viewers or collaborators to log bugs, or raise ideas for the library implementation.
- Projects: Collaborators can view issues in a kanban board and track progress of milestones.
Getting Started With .NET
.NET is a free and open-source cross-platform framework supported by Microsoft where most applications are written in the C# programming language. The platform can be used to build web and desktop applications, as well as command line utilities, services, and class libraries.
Prerequisites
Before diving in you will need the following:
- .NET SDK
- A code editor or IDE:
Creating a Project
The .NET SDK includes a large variety of different project templates that can be viewed here or by running dotnet new list
from a terminal.
We'll be using the classlib
template to create a library called My.Cool.Library
:
mkdir ~/dev/My.Cool.Library
cd ~/dev/My.Cool.Library
dotnet new classlib
The project will be named based on the directory that you run the command from, or can be changed using the --name argument.