2 -> Building and Packaging .NET Core with AppVeyor
As part of that I broke out the log stream component (called KScratchLog) in to a standalone console app. I plan to make this in to a broader console app that can get, push, log stream etc all from the command prompt… but before any of that can happen I figured I should get some CI going.
I decided on AppVeyor because it has .NET Core support, is free and works well with GitHub (like super well).
AppVeyor allows you to run PowerShell and CMD scripts, and the environments that builds are run in will be familiar to most .NET developers.
Most of the heavy lifting and config is done by placing an AppVeyor.yml script in the root of your GitHub Repo.
I had a hunt around, and saw that some projects use custom build scripts with AppVeyor in conjunction with the yml file, but I wanted to try and do it all in the yml.
Searching I found an example yml file by Steven Liekens that I used as a starting point.
Setting up the project.json files
I created my project in Visual Studio. It has a console app and a series of portable projects that are .NET Standard 1.3 based.
The first thing I had to do before I could get it to build on the command line using dotnet build was reference the dependency projects in the project.json file. Visual Studio did not do this automatically as it relies on the references in the .xproj files.
The next step was making sure the build outputted .exe files, which it doesn’t by default. This is done in project.json.
Scott Hanselman’s post on self contained apps in .NET Core was a handy reference for this.
Also make sure you reference the portable projects here too:
The final part of the story was getting the build to work. I played around on the command line on my local machine first to get it going before transporting the commands in to the build_script section of the AppVeyor.yml file.
I also added the ability to build separate platforms in the script, for now only windows is present.
Worth noting is that the AppVeyor platform would not support win10-x64 so I had to change it to win7-x64.
Once the build is completed and dotnet publish is called I package up the file using 7z, before referencing that zip as an artefact.
Finally – I went to the AppVeyor settings and got the MD for the all important AppVeyor build status badge and inserted it in my readme.md file!
Full AppVeyor.yml listing from here
# Don't report back to the mothership
– ps: $Env:LABEL = "CI" + $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0")
– appveyor-retry dotnet restore -v Minimal
– dotnet build "src\KScratch.Entity" -c %CONFIGURATION% -r %PLATFORM% –no-dependencies –version-suffix %LABEL%
– dotnet build "src\KScratch.Contract" -c %CONFIGURATION% -r %PLATFORM% –no-dependencies –version-suffix %LABEL%
– dotnet build "src\KScratch.Portable" -c %CONFIGURATION% -r %PLATFORM% –no-dependencies –version-suffix %LABEL%
– dotnet build "src\KScratchLog" -c %CONFIGURATION% -r %PLATFORM% –no-dependencies –version-suffix %LABEL%
– dotnet publish "src\KScratchLog" -c %CONFIGURATION% -r %PLATFORM% –no-build –version-suffix %LABEL% -o artifacts\%PLATFORM%
– 7z a zip\KScratchLog_%PLATFORM%.zip %APPVEYOR_BUILD_FOLDER%\artifacts\%PLATFORM%\*.*
#- dotnet test "src\KScratch.Tests" -c %CONFIGURATION%
– path: zip\**\*.*
on_finish: # Run the demo to show that it works