Create NuGet packages using AppVeyor

Tags: .NET, CI, Git, NuGet

This blog explains how to create a NuGet package and use AppVeyor as a continuous integration and deployment tool.

I found out about AppVeyor some time ago from Scott's blog - "AppVeyor - A good continuous integration system is a joy to behold". Usually I use TeamCity running on a VM so I didn't have a chance to try it out until recently when I built a NuGet package to generate random users. The NuGet package is based on the https://randomuser.me API – a free API to generate random user data. You would use it in prototyping, testing or filling your database with proper user names, pictures, etc.

AppVeyor is a cloud based continuous integration and delivery service for .NET. It is free for open source projects. It has everything you need and it is really easy to set up. It has a nice Web UI where you configure your build and deployment settings but in this post I will explain the minimum configuration you need to publish a NuGet package using the appveyor.yml file. The reason I prefer to keep my configurations in a file rather than using the UI is that I can version it and when I break something I can fix it fast just by checking the differences in the file.

Every AppVeyor configuration can contain an appveyor.yml file in the root folder. If you have the file and also configure the UI then the YAML file will override the UI settings unless you explicitly disable it in Ignore appveyor.yml settings in the UI.

AppVeyor also has the option to host NuGet packages. Before pushing the NuGet package to https://www.nuget.org I use that to test my packages.

Here's the full YAML file. As you can see, it is self-descriptive and I will explain only the settings which are not clear from the first glance or might be confusing.

version: 0.9.{build}

assembly_info:
  patch: true
  file: AssemblyInfo.cs
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'

platform: Any CPU

configuration: Release

build:
  project: RandomUser.sln
  verbosity: detailed
  publish_nuget: true

before_build:
  - nuget restore

nuget:
  account_feed: true
  project_feed: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/

 

Will let AppVeyor to take care of the release version number. For this purpose {build} is used. Assembly files will be patched with the version value we define in “version”.

In order to publish to NuGet the following should be added to the appveyor.yml file

build:
  publish_nuget: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/

 

You need to get your NuGet API key and encrypt it. AppVeyor offers a tool for encryption at this URL https://ci.appveyor.com/tools/encrypt

In artifact you provide the file name or artifact name to push.

As I said before I prefer to create NuGet packages using AppVeyor feed before pushing them for the first time to nuget.org. For this purpose you need to add the following:

nuget:
  account_feed: true
  project_feed: true

 

Make sure that your project contains a nuspec file in the same folder where your .csproj file is. You can find more information about nuspec here: http://docs.nuget.org/Create/Nuspec-Reference

All the tests are run automatically by the way.

Comments

comments powered by Disqus