Kieren Johnstone
Kieren Johnstone

Reputation: 42013

.NET Core - build/package for net451 on Linux (Travis CI)

I have a (private) Github/Travis CI setup and am trying to validate PRs and publish NuGet packages on a release branch.

Here's my .travis.yml:

language: csharp
os: linux
dist: trusty
sudo: required
env: DOTNETCORE=1
dotnet: 1.0.0-preview2-003121
mono: none
before_script:
  - npm install
script:
  - gulp restore && gulp build && if [ $TRAVIS_BRANCH = 'v0.2' ]; then gulp package; fi

I'm using gulp to do some additional logic and build steps, but basically it invokes everything correctly.. the relevant invocations it does are:

dotnet restore

dotnet build **/project.json

The former succeeds, the latter fails for projects which target net451. Errors look like it can't find framework assemblies, which makes sense, though I'm not sure on the best approach to resolve:

/home/travis/build/Secret/secret/src/Secret.Sample/project.json(7,52): error NU1001: The dependency mscorlib could not be resolved.

(same many times over, also for System, System.Core, System.Xml...)

Here's a sample project.json:

{
    "version": "0.2.0-*",
    "description": "Description..",
  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-alpha1-22107",
    "Microsoft.AspNetCore.Mvc": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Configuration.Json": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Configuration.CommandLine": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Options": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Logging.Console": "1.1.0-alpha1-22107",
    "Microsoft.Extensions.Logging.Debug": "1.1.0-alpha1-22107",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0-alpha1-22107"
  },
    "frameworks": {
        "netstandard1.6": {
        },
        "net451": {
            "buildOptions": {
                "define": [ "SAMPLEY_ON_WINDOWS" ]
            },
            "dependencies": {
                "Microsoft.Extensions.Logging.EventLog": "1.0.0"
            }
        }
    }
}

I found https://github.com/aspnet/Home/issues/1090, where David F indicates "You can't build .NET Framework apps using CoreCLR today." (Nov 2015). Is that stil true, and it's as simple as that? - in which case I should use have Travis just build/test, skipping net451, and Appveyor for build,test and deploy to NuGet?

That wouldn't be my first choice, but if so, how could I optionally tell dotnet build to skip unsupported framework targets?

Ideally, I just need to re-jig my dependencies, or understand frameworkAssemblies, or apt-get something else into the build environment..?

Upvotes: 0

Views: 361

Answers (2)

Technetium
Technetium

Reputation: 6168

  1. You can tell dotnet build and dotnet test to skip over unsupported framework targets by using the -f parameter, and putting in the frameworks that you do want to compile. For example, to compile net451 exclusively, you can run dotnet build -f 451.
  2. Consider using the latest version for mono in your .travis.yml file if you want to ensure you are compatible with the latest release of mono instead of a specific version. That desire depends on your requirements.
  3. You can absolutely build your application for .NET Core on your local box and in Travis CI, yet use it on a .NET Framework application. However, you have to dance around the ".NET Platform Standard" concepts. For using that .NET Core application as a dependency in a traditional .NET Framework application, the .NET Core application would have to be built for .NET Platform Standard 1.X (as you have done with 1.6), which aligns to some version of .NET Framework 4.X.X. See this table to get thoroughly confused on cross operating system compatibility. However, since 4.6.3 is not yet released, you would not yet be able to build a .NET Standard 1.6 library and depend on it in a traditional .NET Framework application. However, you could write your code such that it is compatible with a lower version of the .NET Platform Standard (1.5, 1.4, etc), which are all still compatible with .NET Core, then use that library as a dependency for a released version of a traditional .NET Framework application.

If you'd like to see an example, here is a github repository with a .travis.yml configuration file that builds in .NET Core & Mono on Travis CI for both Linux and Mac OSX, and .NET Core & .NET Framework on Appveyor for Windows.

Upvotes: 1

Kieren Johnstone
Kieren Johnstone

Reputation: 42013

To target .NET Framework targets e.g. net451 in Travis, you need Mono installed.

I fixed by changing mono: none to mono: 4.0.5.

Upvotes: 0

Related Questions