Setup AppVeyor with a C# .NET 5+ library on GitHub to publish msbuild test results and code coverage using CodeCov

Joe Moceri
3 min readJul 6, 2021

AppVeyor rocks, and it’s free for open source projects. So let’s use it. I’m going to be using expression-evaluator as the example project here.

You’ll need to setup your account on AppVeyor and allow it access to your repository. Instructions can be found here.

First, at the root of your github repository, add a file named appveyor.yml. If you navigate to the Settings of your AppVeyor project’s Export YAML page, it will export any custom configuration. In the case of the example project, there are none. Here’s what it looks like.

before_build:- nuget restore ExpressionEvaluatorForDotNet.sln- choco install opencover.portable- choco install codecovtest_script:- cmd: OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test --test-adapter-path:. --logger:Appveyor" -filter:"+[ExpressionEvaluatorForDotNet*]* -[ExpressionEvaluatorForDotNet.Tests*]*" -output:".\coverage.xml" -oldstyleafter_test:- ps: |codecov -f "coverage.xml"

There’s a lot of things going on here, so let’s go through each part.

before_build will be called by AppVeyor and run the following commands.

First, run restore on the solution

nuget restore ExpressionEvaluatorForDotNet.sln

Next, install opencover.portable using choco. This is used to run the OpenCover.Console.exe command below in the test_script.

choco install opencover.portable

Use choco to also get codecov. We’ll use codecov in after_test to upload the resulting .xml code coverage file generated by OpenCover.

choco install codecov

Inside of test_script, there’s a single command to be run.

OpenCover.Console.exe 
-register:user
-target:"C:/Program Files/dotnet/dotnet.exe"
-targetargs:"test --test-adapter-path:. --logger:Appveyor"
-filter:"+[ExpressionEvaluatorForDotNet*]* -[ExpressionEvaluatorForDotNet.Tests*]*"
-output:".\coverage.xml"
-oldstyle

AppVeyor will execute this command. For a full list of the parameters, refer to the documentation here. We use user for register. Specify dotnet.exe as the target, and pass to it “test — test-adapter-path:. — logger:Appveyor” so the full command looks like this

dotnet test --test-adapter-path:. --logger:Appveyor

This will run mstest unit tests and send the output to Appveyor. Make sure to add the Appveyor.TestLogger NuGet package to your Tests project, otherwise this will fail.

The filter specifies which assemblies to include (+), and which to exclude (-), in this case we exclude the unit test project itself and include the source project.

Output specifies the name and where to put the code coverage output .xml file.

We old style for .NET projects (link).

That should be all you need to get setup with AppVeyor. If you check out the latest build for your project, it will look similar to the example below

The unit tests will show up on the unit tests tab

Finally, inside of after_test, there’s one powershell command to run. You’ll need to first go through the getting started for codecov found here to get your github repository setup.

codecov -f "coverage.xml"

This will upload the coverage to codecov on every build.

Refer to the example repository to see it in action.

--

--