An example project for a NuGet Package with code coverage, code quality and auto-deploy to nuget.
The continuous integration platform used is Travis-CI.
There are several variables that need to be set to allow Travis to work correctly with automated builds.
To set environment variables within travis CI follow this guide.
An essential variable that is required is the PROJECT_NAME
variable. This is used to specify the project name for the project and allows for all references to the project name to be updated once from within the CI.
This variable should be set to the project name displayed at the end of the github url - https://github.com/ajwgroup/NugetExampleProject
To be able to push the package to nuget in the deployment stage, the NUGET_KEY
needs to be set.
The NUGET_KEY
can be created by selecting 'API Keys' from the account menu drop down on the nuget website.
From here give the key a friendly name and set the key duration (This is 365 days by default).
If the package has already been published you can select an Available package, or you can specify a Glob pattern for the package(s) that you would like the API key to apply to. It's adviced to create a key for each package that is to be published so that keys can be revoked on a per package basis.
Once the token has been obtained add it to the CI variables as instructed above with the Key name NUGET_KEY
.
Codecov is used for displaying the projects test code coverage. Code coverage can be seen here.
No variables need to be set for the code coverage to published.
SonarCloud is used to analyse the code and provide feedback on several aspects such as code quality, bugs, potential vulnerabilities among others.
The sonarcloud token should be set to the key SONARCLOUD_TOKEN
.
To create and publish documentation for the nuget package DocFx is used within the project. DocFx uses a combination of markdown files and automatically generated content from comments within the code to produce a clean and easily navigable source of documentation and as such is recommended, though not necessary.
Note: Ensure there is a branch 'gh-pages' available before allowing the CI to attempt to publish.
In the settings for the github project under the 'GitHub Pages' section, pick the 'gh-pages' branch as the source for the pages site.
To provide travis with the ability to deploy the documentation you’ll need to generate a personal access token with the public_repo permission.
Since the token should be private, you’ll want to pass it to Travis securely in your repository settings. To generate a personal token follow this guide.
Once the token has been generated and stored as GITHUB_TOKEN
within travis, the CI for this example project should be able to publish any static files stored in {PROJECT_NAME}/_site
, this is the default location used by DocFx to store the static files.
For more information on deploying to github pages read this guide to deploy to github pages.
For a consistent look it's recommended to use badges available from shields.io. Example Badges can be seen below.
- Add in automated documentation generation
- Generate a visual studio template project