mono icon indicating copy to clipboard operation
mono copied to clipboard

.NET 5 / C# 9 multi targeting on macOS issue

Open mfkl opened this issue 3 years ago • 4 comments

Steps to Reproduce

  1. Clone https://github.com/mfkl/mac-multitarget-net5-cs9 on macOS
  2. Build with msbuild
  3. See error

Current Behavior

There are errors when building a multitarget solution with the MSBuildExtra SDK on macOS only (OK on Windows), when using TFMs like net5.0 and xamarin.ios10. It seems Mono is using an out of date SDK.

Using a more recent-ish nightly Mono build results in a C# compiler error CSC : error CS1900: Warning level must be in the range 0-4. Setting that explicitly in the csproj gets ignored (probably another bug?).

Expected Behavior

It should build fine, as it does on Windows.

On which platforms did you notice this

[x] macOS

Version Used:

6.12, 6.13

Stacktrace

    Starting: Build
    ==============================================================================
    Task         : MSBuild
    Description  : Build with MSBuild
    Version      : 1.179.0
    Author       : Microsoft Corporation
    Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/msbuild
    ==============================================================================
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild /version /nologo
    /Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild /Users/runner/work/1/s/repro-dotnet-5-mac.csproj
    Microsoft (R) Build Engine version 16.6.0 for Mono
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 2/9/2021 4:10:29 AM.
    Restoring packages for /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/25b452314b6748e2ae47acfeeff57bfb/d32d6f5b3e69424b8453584b01696220.proj...
      GET https://api.nuget.org/v3-flatcontainer/msbuild.sdk.extras/index.json
      OK https://api.nuget.org/v3-flatcontainer/msbuild.sdk.extras/index.json 73ms
      GET https://api.nuget.org/v3-flatcontainer/msbuild.sdk.extras/3.0.23/msbuild.sdk.extras.3.0.23.nupkg
      OK https://api.nuget.org/v3-flatcontainer/msbuild.sdk.extras/3.0.23/msbuild.sdk.extras.3.0.23.nupkg 6ms
    Installing MSBuild.Sdk.Extras 3.0.23.
    Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" on node 1 (default targets).
    Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (1) is building "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (1:4) on node 1 (Build target(s)).
    /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(127,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 5.0.  Either target .NET Core 3.1 or lower, or use a version of the .NET SDK that supports .NET Core 5.0. [/Users/runner/work/1/s/repro-dotnet-5-mac.csproj]
    Done Building Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (Build target(s)) -- FAILED.
    Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (1) is building "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (1:5) on node 1 (Build target(s)).
    PrepareForBuild:
      Creating directory "bin/Debug/xamarin.ios10/".
      Creating directory "obj/Debug/xamarin.ios10/".
    _BeforeCoreCompileInterfaceDefinitions:
    Skipping target "_BeforeCoreCompileInterfaceDefinitions" because it has no inputs.
    _BeforeCoreCompileInterfaceDefinitions:
    Skipping target "_BeforeCoreCompileInterfaceDefinitions" because it has no inputs.
    _BeforeCoreCompileInterfaceDefinitions:
    Skipping target "_BeforeCoreCompileInterfaceDefinitions" because it has no inputs.
    _CoreCompileInterfaceDefinitions:
    Skipping target "_CoreCompileInterfaceDefinitions" because it has no inputs.
    _BeforeCoreCompileImageAssets:
    Skipping target "_BeforeCoreCompileImageAssets" because it has no inputs.
    _BeforeCoreCompileImageAssets:
    Skipping target "_BeforeCoreCompileImageAssets" because it has no inputs.
    _BeforeCoreCompileImageAssets:
    Skipping target "_CoreOptimizePropertyLists" because it has no inputs.
    _CoreOptimizeLocalizationFiles:
    Skipping target "_CoreOptimizeLocalizationFiles" because it has no inputs.
    /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file '/Users/runner/work/1/s/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/runner/work/1/s/repro-dotnet-5-mac.csproj]
    Done Building Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (Build target(s)) -- FAILED.
    Done Building Project "/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (default targets) -- FAILED.

https://github.com/novotnyllc/MSBuildSdkExtras/issues/255

mfkl avatar Feb 09 '21 04:02 mfkl

2021-03-01T06:19:47.8518930Z   Using shared compilation with compiler from directory: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Roslyn (TaskId:57)
2021-03-01T06:19:48.2074080Z   Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100) (TaskId:57)
2021-03-01T06:19:48.2075750Z   Copyright (C) Microsoft Corporation. All rights reserved. (TaskId:57)
2021-03-01T06:19:48.2110240Z CSC : error CS1617: Invalid option '9.0' for /langversion. Use '/langversion:?' to list supported values. [/Users/runner/work/1/s/src/LibVLCSharp/LibVLCSharp.csproj]
2021-03-01T06:19:48.2117810Z   Output Item(s): CscCommandLineArgs= (TaskId:57)
2021-03-01T06:19:48.2120100Z Done executing task "Csc" -- FAILED. (TaskId:57)

mfkl avatar Mar 01 '21 06:03 mfkl

Here is the long instruction on how to bump compiler version: https://github.com/mono/mono/blob/main/external/how-to-bump-roslyn-binaries.md

ArsenShnurkov avatar Aug 27 '21 16:08 ArsenShnurkov

Hmm, this seems to still be happening with .NET 6.

It is currently not possible to have a single csproj file which targets both pre and post .NET 6 world. I guess Mono would need an up to date MSBuild, at least, and I think that's unlikely to happen? Is the guidance to use 2 csprojs for libs that want to support pre net6 era?

This is with net6 https://github.com/mfkl/mac-multitarget-net5-cs9

(_CheckForUnsupportedNETCoreVersion target) -> 
  /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(127,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 6.0.  Either target .NET Core 3.1 or lower, or use a version of the .NET SDK that supports .NET Core 6.0. [/Users/runner/work/1/s/repro-dotnet-5-mac.csproj]


"/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (default target) (1) ->
"/Users/runner/work/1/s/repro-dotnet-5-mac.csproj" (Build target) (1:5) ->
(ResolvePackageAssets target) -> 
  /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1004: Assets file '/Users/runner/work/1/s/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/runner/work/1/s/repro-dotnet-5-mac.csproj]

mfkl avatar Nov 22 '21 10:11 mfkl

Any updates on this? @mfkl did you find any workarounds?

busec0 avatar Jun 05 '22 09:06 busec0