This is just a brief post that I’m hoping may help some people migrate to use .NET Core 2.0 SDK on Travis. TL;DR: see the end of the post for a sample configuration.
Yesterday (August 15th), .NET Core 2.0 was fully released. Wonderfully, Travis already supports it. You just need
dotnet: 2.0.0 in your YAML file.
I decided to experiment with upgrading the Noda Time build to require .NET Core 2.0 SDK. To be clear, I’m not doing anything in the code that requires 2.0, but it simplifies my build scripts:
- I no longer need to run
dotnet restoreto build/run
- The bug in the CLI requiring project files has been fixed
- The 2.0 CLI has much nicer output if you specify a TFM that’s not supported by your project
netcoreapp2.0 means I’ll be able to run my benchmarks against that as well, which is going to be very interesting. However, my tests still target
netcoreapp1.0, and that’s where I ran into problems.
Having done the bare minimum to try using 2.0 (edit
.travis.yml) I ran into this error:
The specified framework 'Microsoft.NETCore.App', version '1.0.5' was not found. - Check application dependencies and target a framework version installed at: / - Alternatively, install the framework version '1.0.5'.
That makes sense. Although
netcoreapp2.0 is compatible with
netstandard1.0 (i.e. you can use libraries targeted to
netstandard1.0 in a 2.0 environment) an application targeting
netcoreapp1.0 really needs a 1.0 runtime.
So, we need to install just the runtime as well. I’d expected this to be potentially painful, but it’s really not. You just need an
addons section in the YAML file:
addons: apt: sources: - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main' key_url: 'https://packages.microsoft.com/keys/microsoft.asc' packages: - dotnet-sharedframework-microsoft.netcore.app-1.0.5
Note that in my case, I want
netcoreapp1.0 – if you need
netcoreapp1.1, you’d probably install
So, aside from comments etc, my new Travis configuration will look like this:
language: csharp mono: none dotnet: 2.0.0 dist: trusty addons: apt: sources: - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main' key_url: 'https://packages.microsoft.com/keys/microsoft.asc' packages: - dotnet-hostfxr-1.0.1 - dotnet-sharedframework-microsoft.netcore.app-1.0.5 script: - build/travis.sh
I can now build with the 2.0 SDK, and run tests under both
I’m hoping it’s just as simple on AppVeyor when that supports 2.0 as well…