A private feed for your organization via AppVeyor

If you're working in the .NET stack regularly and don't know AppVeyor yet, it's definitely worth checking out.

AppVeyor is a CI system focused in .NET projects. You can easily link it to GitHub, Bitbucket and Visual Studio Online. It can build your project, run tests, deploy, and... publish to NuGet.

This is what I will cover in this post today.

When you have a piece of code that is repeated across two or more projects, it can be interesting, nay recommended, to put in in its own library. And AppVeyor includes its own private NuGet feed, making it easy to just commit code, and have it appear in the feed. No manual steps needed!

It just takes a few steps to set up, and you're good to go.

nuspec file

First, add a nuspec file to the project you want to publish and fill in the details. For more info on what to put in there, check out the docs. If you've been publishing manually, you already have this file.

appveyor.yml

You can set up AppVeyor from the UI, but I prefer the YAML file, because it allows me to put this file in source control and see its changes and history.

This is an example of a simple file:

version: 1.0.{build}

branches:  
  only:
  - /\d*\.\d*\.\d*/

image: Visual Studio 2015

configuration: Release

platform: Any CPU

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

init:  
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
- ps: >-
      if ($env:APPVEYOR_REPO_TAG -eq "true") 
      { 
        $version = "$env:APPVEYOR_REPO_TAG_NAME.$env:APPVEYOR_BUILD_NUMBER" 
        Write-Host "Setting version to $version" 
        Update-AppveyorBuild -Version "$version" 
      } 
      else 
      { 
        $version = "$env:APPVEYOR_BUILD_VERSION" 
        Write-Host "Setting version to $version because there is no tag" 
        Update-AppveyorBuild -Version "$version" 
      } 

before_build:  
- cmd: nuget restore

build:  
  project: Foodpairing.Messaging.sln
  publish_nuget: true
  publish_nuget_symbols: true
  verbosity: minimal

What this does is:

  • only build tagged commits (in the form like 3.1.2)
  • set the version of the DLL to the version of the tag
  • publish to the private AppVeyor NuGet feed

Using the package

To use this package, we need to add our private feed to our NuGet sources in Visual Studio. Go to Tools > NuGet Package Manager > Package Manager Settings and add the source. You can find the URL by going to AppVeyor, clicking the dropdown of your account, and choosing NuGet. If you're already logged in, go to https://ci.appveyor.com/nuget.

As this is a private feed, Visual Studio will prompt you for your credentials when you use it.

Conclusion

If you're already using AppVeyor, you can easily set up a private NuGet feed, with little configuration or manual steps. If you're not using AppVeyor, check it out. It features a private NuGet feed :)