Search code examples
msbuildasp.net-coremono.net-coretravis-ci

Building VS 2017 MSBuild csproj Projects with Mono on Linux


I have .NET Core projects I am trying to build using Travis CI on Mac and Linux using the latest Mono and .NET Core 1.0.1 tooling (MSBuild based csproj tooling). They target netstandard1.6.1, net45 and net461. The error I get from Travis CI is:

/usr/share/dotnet/sdk/1.0.1/Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

Does Mono not support VS 2017 MSBuild based csproj projects? How can I get my projects to build?


Solution

  • .NET Framework Targeting Pack Nuget Packages

    You can now build new style csproj projects with Mono on Linux by adding a NuGet package:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup Label="Build">
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup Label="Package References">
        <PackageReference 
          Include="Microsoft.NETFramework.ReferenceAssemblies" 
          PrivateAssets="All" 
          Version="1.0.0-preview.2" />
      </ItemGroup>
    
    </Project>
    

    More information can be found on the Microsoft/dotnet GitHub page. At the time of writing it's in preview but I've found that it does work. The only gotcha I discovered is that dotnet test with xUnit projects does not work and is not a supported scenario according to the xUnit author.