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}
image: Visual Studio 2022
configuration: Release
platform: Any CPU

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

# For .NET Core, .NET Standard, ASP.NET Core:
dotnet_csproj:
  patch: true
  file: '**\*.csproj'
  version: '{version}'
  version_prefix: '{version}'
  package_version: '{version}'
  assembly_version: '{version}'
  file_version: '{version}'
  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: dotnet restore # or nuget restore for classic .NET

build:
  project: My.Solution.sln
  verbosity: minimal

deploy:
  - provider: NuGet
    server: <your private nuget feed>
    api_key:
      secure: <your secured api key>
    on:
      APPVEYOR_REPO_TAG: true # only publish tags

What this does is:

  • set the version of the DLL to the version of the tag, if present (like 3.1.2)
  • publish to the private AppVeyor NuGet feed, if there is a tag

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.

You can also find your API Key there. Secure it using this tool: https://ci.appveyor.com/tools/encrypt.

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 🙂

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.