Building VS 2017 MSBuild csproj Projects with Mono on Linux

I have .NET Core projects I'm trying to build using Travis CI on Mac and Linux using the latest Mono and .NET Core 1.0. 1 (MSBuild-based csproj toolkit). They target netstandard1.6.1 , net45 and net461 . The error I get from Travis CI :

/usr/share/dotnet/sdk/1.0.1/Microsoft.Common.CurrentVersion.targets(1111,5): MSB3644 error: reference assemblies for the framework ".NETFramework, Version = v4.5" were not found. To solve this problem, install the SDK or Targeting Pack for this version of the framework or reconfigure the application to the version of the framework for which you have an SDK or targeting package. Please note that assemblies will be allowed from the Global Cache (GAC) and will be used instead of control assemblies. Therefore, your assembly may not be designed correctly for the framework that you plan to use.

Does Mono not support VS-2019 csproj based MSBuild projects? How can I create my projects?

+8
source share
4 answers

Targeting Packages for the .NET Framework

Now you can create new Mono-style csproj projects for Linux by adding the NuGet package:

 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup Label="Build"> <OutputType>Exe</OutputType> <TargetFramework>net472</TargetFramework> </PropertyGroup> <ItemGroup Label="Package References"> <PackageReference Condition="'$(OS)' != 'Windows_NT'" Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0-preview.2" /> </ItemGroup> </Project> 

For more information, see the Microsoft / dotnet GitHub page. At the time of this writing in the preview, but I found that it works. The only thing I discovered is that dotnet test does not work with xUnit projects and is not a supported script, according to the author of xUnit.

0
source

As far as I know, there are two options:

  • Use the FrameworkPathOverride environment variable as described in this release to point to them.

  • Limit the build of Travis only to the build against .NET Core. It is much easier in my experience.

Here is the Noda Time .travis.yml file that I will use for Noda Time when I can migrate - at least in advance, but it collects ...

 language: csharp mono: none dotnet: 1.0.1 dist: trusty script: - dotnet restore src/NodaTime - dotnet restore src/NodaTime.Test - dotnet restore src/NodaTime.Serialization.Test - dotnet build src/NodaTime -f netstandard1.3 - dotnet build src/NodaTime.Test -f netcoreapp1.0 - dotnet build src/NodaTime.Serialization.Test -f netcoreapp1.0 - dotnet run -p src/NodaTime.Test/*.csproj -f netcoreapp1.0 -- --where=cat!=Slow - dotnet run -p src/NodaTime.Serialization.Test/*.csproj -f netcoreapp1.0 

A few comments about this:

  • Unlike earlier SDKs, now we need to restore each project separately - there is no big "top-level dotnet recovery" :(
  • I was surprised when this does not work on dist: xenial , but it is not. (He claims that the environment does not support .NET Core.) I think this will change.
  • We use NUnit, and for now, the only way to test in the new SDK is to use NUnitLite, hence dotnet run to run the tests.
  • I am a little surprised that I can’t just specify the directory name for dotnet run (according to dotnet restore dotnet build and dotnet build ), but it seems to be so. I will track down the error message ...

In any case, I would also recommend having a Windows-based CI build to verify that everything is built and works on Windows (ideally testing every environment you support).

+6
source

As of yesterday (May 5), @dasMulli noted that Mono has released Mono 5.0 Beta 2 (5.0.0.94), which works with .NET Core! Here is his post on dotnet / sdk # 335 . Here is the link to the latest beta version

My .travis.yml file looks like this:

 sudo: required dist: trusty language: csharp solution: MySolution.sln mono: - beta dotnet: 1.0.3 install: - nuget restore MySolution.sln - dotnet restore MySolution.sln script: - msbuild /t:Rebuild MySolution.sln 
+1
source

Mono supports the creation of VS2017.Net Framework projects, as it now uses msbuild.

To make it work on Travis CI, this is a bit complicated, but it should work:

  - wget -q https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb - sudo dpkg -i packages-microsoft-prod.deb - wget -q http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/gcc-5-base_5.4.0-6ubuntu1~16.04.9_amd64.deb - sudo dpkg -i gcc-5-base_5.4.0-6ubuntu1~16.04.9_amd64.deb - wget -q http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.9_amd64.deb - sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.9_amd64.deb - wget -q http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu55_55.1-7ubuntu0.4_amd64.deb - sudo dpkg -i libicu55_55.1-7ubuntu0.4_amd64.deb - sudo apt-get install apt-transport-https - sudo apt-get install -y libicu55 - sudo apt-get install dotnet-runtime-deps-2.1 - sudo apt-get install dotnet-runtime-2.1 - sudo apt-get install aspnetcore-runtime-2.1 - sudo apt-get install dotnet-sdk-2.1 

Essentially, you need to manually install dotnet-sdk manually and all its dependencies.

Then just call msbuild:

  - msbuild /p:Configuration=Release Solution.sln 
+1
source

Source: https://habr.com/ru/post/1015686/


All Articles