Bug 256342 - devel/msbuild: default targets are unusable with lang/mono5.20 and lang/mono6.8
Summary: devel/msbuild: default targets are unusable with lang/mono5.20 and lang/mono6.8
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-mono (Nobody)
URL:
Keywords: needs-patch
Depends on:
Blocks: 273001
  Show dependency treegraph
 
Reported: 2021-06-01 15:46 UTC by Jan Beich
Modified: 2023-09-05 06:19 UTC (History)
3 users (show)

See Also:


Attachments
0001-games-openra-compat-for-devel-msbuild-16.1.patch (3.65 KB, patch)
2023-08-13 23:21 UTC, Marcin Cieślak
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2021-06-01 15:46:44 UTC
$ pkg install -A msbuild
$ pkg delete -f mono
$ pkg install -A mono6.8
$ pkg set -n mono6.8:mono
$ pkg set -o lang/mono6.8:lang/mono

$ cat hello.cs
namespace HelloWorld
{
    class Hello {         
        static void Main(string[] args)
        {
            System.Console.WriteLine("Hello World!");
        }
    }
}

$ cat hello.csproj
<Project>
  <ItemGroup>
    <Compile Include="hello.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

$ msbuild hello.csproj
Microsoft (R) Build Engine version 42.42.42.42 ( Fri May 14 04:36:25 UTC 2021) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 6/1/2021 3:42:43 PM.
Project "/tmp/hello.csproj" on node 1 (default targets).
/usr/local/lib/mono/msbuild/15.0/bin/Microsoft.CSharp.CurrentVersion.targets(331,5): error MSB4019: The imported project "/usr/local/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [/tmp/hello.csproj]
Done Building Project "/tmp/hello.csproj" (default targets) -- FAILED.

Build FAILED.

"/tmp/hello.csproj" (default target) (1) ->
  /usr/local/lib/mono/msbuild/15.0/bin/Microsoft.CSharp.CurrentVersion.targets(331,5): error MSB4019: The imported project "/usr/local/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [/tmp/hello.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.27
Comment 1 Marcin Cieślak 2023-08-03 20:00:46 UTC
Is it the same with mono5.20 ? (can't use pkg right now to quickly check due to pending OpenSSL 3.0 upgrade)

Looks like starting with mono5.20 we have the directory is now called "Current" instead of "15.0"

> grep Microsoft.CSharp.Core.targets /usr/ports/lang/mono*/pkg-plist
/usr/ports/lang/mono/pkg-plist:lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets
/usr/ports/lang/mono5.10/pkg-plist:lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets
/usr/ports/lang/mono5.20/pkg-plist:lib/mono/msbuild/Current/bin/Roslyn/Microsoft.CSharp.Core.targets
/usr/ports/lang/mono6.8/pkg-plist:lib/mono/msbuild/Current/bin/Roslyn/Microsoft.CSharp.Core.targets

Do we need a newer msbuild or is symlink enough of a solution?
Comment 2 Marcin Cieślak 2023-08-06 21:37:11 UTC
A manual workaround is for this is the following:

# ln -s ../../Current/bin/Roslyn /usr/local/lib/mono/msbuild/15.0/bin/Roslyn

This seems to fix most of the port breakage with 6.8 reported in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=238089#c79

I don't know if we can make an older msbuild 15 and newer msbuild 16+ (preferred for mono 6.8+) to co-exist.

Maybe we should go for a bold move an replace devel/msbuild with 16.9.0 (or later) and lang/mono with 6.12+

(or maybe there is a fix for this that does not break removal of mono6.8 and reinstallation of mono 5.10 - this port needs to install lib/mono/msbuild/15.0/bin/Roslyn that is not a symbolic link).
Comment 3 Jan Beich freebsd_committer freebsd_triage 2023-08-07 15:50:17 UTC
(In reply to Marcin Cieślak from comment #2)
> # ln -s ../../Current/bin/Roslyn /usr/local/lib/mono/msbuild/15.0/bin/Roslyn

I confirm, this fixes lang/mono5.20 while lang/mono6.8 needs more.

$ msbuild hello.csproj
Microsoft (R) Build Engine version 42.42.42.42 ( Tue Aug  1 17:21:05 UTC 2023) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 8/7/2023 1:23:36 PM.
Project "/tmp/hello.csproj" on node 1 (default targets).
/usr/local/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.Managed.Core.targets(60,27): error MSB4184: The expression ""hello.cs".GetPathsOfAllDirectoriesAbove()" cannot be evaluated. Method 'System.String.GetPathsOfAllDirectoriesAbove' not found. [/tmp/hello.csproj]
Done Building Project "/tmp/hello.csproj" (default targets) -- FAILED.

Build FAILED.

"/tmp/hello.csproj" (default target) (1) ->
  /usr/local/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.Managed.Core.targets(60,27): error MSB4184: The expression ""hello.cs".GetPathsOfAllDirectoriesAbove()" cannot be evaluated. Method 'System.String.GetPathsOfAllDirectoriesAbove' not found. [/tmp/hello.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.25

> Maybe we should go for a bold move an replace devel/msbuild with 16.9.0 (or later) and lang/mono with 6.12+

For games/openra 20200503 -> 20210321 (the latest is 20230225 but requires dotnet instead of mono) I need at least lang/mono5.20 due to https://github.com/openra/openra/commit/19b02875c7da
OpenBSD Ports has openra-20210321 with mono-6.12, so skipping 5.20 (and 6.8) should be fine.
Comment 4 Alastair Hogge 2023-08-07 21:24:10 UTC
(In reply to Marcin Cieślak from comment #2)

I made an attempt to update mono6, based on Sean Champ's patch at bug #262637. msbuild is more involved, and I was unable to build dotnet from source. If there are any pointers or previous work on updating msbuild, that would be most excellent.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-08-08 11:22:48 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=bcd90622c73cdc090877a2f8173cf50a8e8e611f

commit bcd90622c73cdc090877a2f8173cf50a8e8e611f
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2023-08-08 09:16:02 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2023-08-08 11:16:45 +0000

    lang/mono*: add compat symlink for devel/msbuild < 16

    /usr/local/lib/mono/msbuild/15.0/bin/Microsoft.CSharp.CurrentVersion.targets(331,5): error MSB4019: The imported project "/usr/local/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    PR:             256342
    Suggested by:   Marcin Cieślak
    Regressed by:   https://github.com/mono/mono/commit/1717687e16dd

 emulators/mesen/Makefile | 4 ++--
 games/openbve/Makefile   | 4 ++--
 games/openra/Makefile    | 4 ++--
 lang/fsharp/Makefile     | 6 +-----
 lang/mono5.20/Makefile   | 6 +++++-
 lang/mono6.8/Makefile    | 6 +++++-
 6 files changed, 17 insertions(+), 13 deletions(-)
Comment 6 Marcin Cieślak 2023-08-13 22:41:56 UTC
(In reply to Jan Beich from comment #3)

I've checked this and the problems is that mono 6.8 macro files invoke method GetPathsOfAllDirectoriesAbove added in https://github.com/dotnet/msbuild/pull/4231 and first released in

https://github.com/dotnet/msbuild/releases/tag/v16.1.76.45076

we are still installing 15.8 pre-release as devel/msbuild

to reach parity with 6.8 we should have at least MSBuild 16.4 according to
https://www.mono-project.com/docs/about-mono/versioning/

Even for 5.20 we might find some issues, as it got released to use MSBuild 16.0
Comment 7 Marcin Cieślak 2023-08-13 23:21:28 UTC
Created attachment 244075 [details]
0001-games-openra-compat-for-devel-msbuild-16.1.patch

Unbreak games/openra for lang/mono6.8 with devel/msbuild < 16.1

We could also try to patch the .editorconfig support
out of the Microsoft.Managed.Core.targets
Comment 8 Jan Beich freebsd_committer freebsd_triage 2023-09-05 06:19:40 UTC
(In reply to Marcin Cieślak from comment #7)
It helps and need to be applied in all msbuild consumers but fragile: lang/mono 6.8.* -> 6.12.* requires adding -p:DiscoverGlobalAnalyzerConfigFiles=false. lang/mono6.* itself has some bugs before it can be made default. Besides, updating games/openra is still blocked on newer devel/msbuild thus I'm not interested yet e.g.,

StreamExts.cs(13,14): error CS0234: The type or namespace name 'Buffers' does not exist in the namespace 'System' (are you missing an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
CSC : error CS1705: Assembly 'System.Threading.Channels' with identity 'System.Threading.Channels, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' uses 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'netstandard' with identity 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
CSC : error CS1705: Assembly 'ICSharpCode.SharpZipLib' with identity 'ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' uses 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'netstandard' with identity 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
MiniYaml.cs(152,51): error CS0246: The type or namespace name 'ReadOnlyMemory<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
Exts.cs(603,10): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
Exts.cs(572,30): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
Exts.cs(569,3): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
StreamExts.cs(161,29): error CS0246: The type or namespace name 'ReadOnlyMemory<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
Sync.cs(58,42): error CS0246: The type or namespace name 'ILGenerator' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
CSC : error CS1705: Assembly 'Linguini.Bundle' with identity 'Linguini.Bundle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'netstandard' with identity 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
CSC : error CS1705: Assembly 'Mono.Nat' with identity 'Mono.Nat, Version=3.0.0.0, Culture=neutral, PublicKeyToken=6c9468a3c21bc6d1' uses 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'netstandard' with identity 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]
Graphics/SpriteFont.cs(248,19): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?) [.../OpenRA-release-20230225/OpenRA.Game/OpenRA.Game.csproj]