dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

msbuild from mono on Ubuntu not finding 3.5 framework assemblies #3104

Open fubar-coder opened 6 years ago

fubar-coder commented 6 years ago

Steps to reproduce

  1. Download the test project
  2. dotnet restore
  3. msbuild

Expected behavior

msbuild should be able to find the Microsoft.Build.Utilities.v3.5 assembly . In /usr/lib/mono/xbuild-frameworks/.NETFramework/v3.5 is a sub-directory RedistList which contains a FrameworkList.xml file. This points to the correct location of the Microsoft.Build.Utilities.v3.5 assembly with the relative path ../../../../3.5-api/ pointing to /usr/lib/mono/3.5-api.

My assumption is, that - when the IncludeFramework attribute exists - the assemblies in the TargetFrameworkDirectory are ignored. The same project file works under Windows.

Actual behavior

icrosoft (R) Build Engine version 15.4.0.0 ( Wed Nov 29 14:56:11 UTC 2017) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 3/19/2018 6:12:36 PM.
Project "/home/mjunker/test/test.csproj" on node 1 (default targets).
ResolveAssemblyReferences:
  Primary reference "Microsoft.Build.Utilities.v3.5".
/usr/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2057,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Build.Utilities.v3.5". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/home/mjunker/test/test.csproj]
          For SearchPath "{TargetFrameworkDirectory}".
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.5/Microsoft.Build.Utilities.v3.5.winmd", but it didn't exist.
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.5/Microsoft.Build.Utilities.v3.5.dll", but it didn't exist.
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.5/Microsoft.Build.Utilities.v3.5.exe", but it didn't exist.
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.0/Microsoft.Build.Utilities.v3.5.winmd", but it didn't exist.
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.0/Microsoft.Build.Utilities.v3.5.dll", but it didn't exist.
          Considered "/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.0/Microsoft.Build.Utilities.v3.5.exe", but it didn't exist.
          Considered "/usr/lib/mono/2.0-api/Microsoft.Build.Utilities.v3.5.winmd", but it didn't exist.
          Considered "/usr/lib/mono/2.0-api/Microsoft.Build.Utilities.v3.5.dll", but it didn't exist.
          Considered "/usr/lib/mono/2.0-api/Microsoft.Build.Utilities.v3.5.exe", but it didn't exist.
          For SearchPath "{RawFileName}".
          Considered treating "Microsoft.Build.Utilities.v3.5" as a file name, but it didn't exist.
GenerateBindingRedirects:
  No suggested binding redirects from ResolveAssemblyReferences.
CoreCompile:
  /usr/lib/mono/4.5/csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;DEBUG;NET35 /highentropyva- /reference:/usr/lib/mono/2.0-api/Microsoft.Build.Framework.dll /reference:/usr/lib/mono/2.0-api/mscorlib.dll /reference:/usr/lib/mono/2.0-api/System.Core.dll /reference:/usr/lib/mono/2.0-api/System.Data.dll /reference:/usr/lib/mono/2.0-api/System.dll /reference:/usr/lib/mono/2.0-api/System.Drawing.dll /reference:/usr/lib/mono/2.0-api/System.Runtime.Serialization.dll /reference:/usr/lib/mono/2.0-api/System.Xml.dll /reference:/usr/lib/mono/2.0-api/System.Xml.Linq.dll /debug+ /debug:portable /filealign:512 /optimize- /out:obj/Debug/net35/test.exe /target:exe /warnaserror- /utf8output /deterministic+ Program.cs obj/Debug/net35/test.AssemblyInfo.cs /warnaserror+:NU1605
Program.cs(9,43): error CS0234: The type or namespace name 'Utilities' does not exist in the namespace 'Microsoft.Build' (are you missing an assembly reference?) [/home/mjunker/test/test.csproj]
Done Building Project "/home/mjunker/test/test.csproj" (default targets) -- FAILED.

Build FAILED.

"/home/mjunker/test/test.csproj" (default target) (1) ->
(ResolveAssemblyReferences target) ->
  /usr/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2057,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Build.Utilities.v3.5". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/home/mjunker/test/test.csproj]

"/home/mjunker/test/test.csproj" (default target) (1) ->
(CoreCompile target) ->
  Program.cs(9,43): error CS0234: The type or namespace name 'Utilities' does not exist in the namespace 'Microsoft.Build' (are you missing an assembly reference?) [/home/mjunker/test/test.csproj]

    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.20

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 15.4.0.0 ( Wed Nov 29 14:56:11 UTC 2017) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

15.4.0.0

OS info:

NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
ghost commented 6 years ago

Try passing the property /p:FrameworkPathOverride=/usr/lib/mono/xbuild-frameworks/.NETFramework/v3.5 (or define in csproj file). See https://github.com/dotnet/sdk/issues/335#issuecomment-371484670.

fubar-coder commented 6 years ago

@kasper3 No, this doesn't work, because now it's unable to find any assembly at all, because the v3.5 assemblies are in the path specified by the TargetFrameworkDirectory (i.e. /usr/lib/mono/3.5-api). This target framework directory only contains the difference between v3.5 and v3.0 and the other assemblies are in different framework paths.

rainersigwald commented 6 years ago

@radical Can you take a look at this (or suggest a better place to ask)?

mfilippov commented 6 years ago

@fubar-coder Try to use /p:TargetFrameworkRootPath=/usr/lib/mono/xbuild-frameworks