Properly support versioning of references without relying on HintPath
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Steps to reproduce
Consider a case where you have two versions of the same assembly (`apt install gtk-sharp2 gtk-sharp3`), with wildly different API/ABI, both installed in the GAC:
```
directhex@bionicvm:~/Projects/msbuildissue$ gacutil -l gtk-sharp
The following assemblies are installed into the GAC:
gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f
gtk-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f
Number of items = 2
```
And a very simple project which depends on the API in the LOWER VERSIONED library:
```
directhex@Josephs-MBP:/tmp/msbuildissue$ cat code.cs
using Gtk;
using System;
class Hello {
static void Main()
{
Application.Init ();
Window window = new Window ("helloworld");
window.Show();
Application.Run ();
}
}
directhex@Josephs-MBP:/tmp/msbuildissue$ cat msbuildissue.csproj
Debug
AnyCPU
{D1FFA0DC-0ACC-4108-ADC1-2A71122C09AF}
bin\$(Configuration)\
v4.6.1
glib-sharp-2.0
gtk-sharp-2.0
```
### Expected behavior
Clearly, the assembly references there are using the full versioned signature of the desired library, so that's the assembly which should be used when building
### Actual behavior
```
directhex@bionicvm:~/Projects/msbuildissue$ msbuild
Microsoft (R) Build Engine version 15.1.8.0 ( Wed Sep 5 19:27:37 UTC 2018) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 9/8/2018 8:14:07 AM.
Project "/home/directhex/Projects/msbuildissue/msbuildissue.csproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "bin/Debug/".
Creating directory "obj/Debug/".
CoreCompile:
/usr/lib/mono/msbuild/15.0/bin/Roslyn/csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:anycpu32bitpreferred /highentropyva+ /reference:/usr/lib/mono/gac/glib-sharp/3.0.0.0__35e10195dab3c99f/glib-sharp.dll /reference:/usr/lib/mono/gac/gtk-sharp/3.0.0.0__35e10195dab3c99f/gtk-sharp.dll /reference:/usr/lib/mono/4.6.1-api/mscorlib.dll /reference:/usr/lib/mono/4.6.1-api/System.Core.dll /reference:/usr/lib/mono/4.6.1-api/System.dll /debug:portable /out:obj/Debug/msbuildissue.exe /subsystemversion:6.00 /target:exe /utf8output code.cs "/tmp/.NETFramework,Version=v4.6.1.AssemblyAttributes.cs"
code.cs(8,29): error CS0012: The type 'Application' is defined in an assembly that is not referenced. You must add a reference to assembly 'gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'. [/home/directhex/Projects/msbuildissue/msbuildissue.csproj]
code.cs(13,29): error CS0012: The type 'Application' is defined in an assembly that is not referenced. You must add a reference to assembly 'gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'. [/home/directhex/Projects/msbuildissue/msbuildissue.csproj]
Done Building Project "/home/directhex/Projects/msbuildissue/msbuildissue.csproj" (default targets) -- FAILED.
Build FAILED.
"/home/directhex/Projects/msbuildissue/msbuildissue.csproj" (default target) (1) ->
(CoreCompile target) ->
code.cs(8,29): error CS0012: The type 'Application' is defined in an assembly that is not referenced. You must add a reference to assembly 'gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'. [/home/directhex/Projects/msbuildissue/msbuildissue.csproj]
code.cs(13,29): error CS0012: The type 'Application' is defined in an assembly that is not referenced. You must add a reference to assembly 'gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'. [/home/directhex/Projects/msbuildissue/msbuildissue.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:01.60
```
Clearly, the assembly version is not being used correctly.
In the oldern days, Mono's MSBuild reimplementation, XBuild, worked around it using a standardized-ish mechanism for Linux software development called `pkg-config`. In the above csproj, the `Package` tags on the `Reference` mean "for this reference, consider the assemblies in the file $PKG_CONFIG_PATH/gtk-sharp-2.0.pc" and building with xbuild yields:
```
directhex@bionicvm:~/Projects/msbuildissue$ xbuild
>>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<
XBuild Engine Version 14.0
Mono, Version 5.16.0.147
Copyright (C) 2005-2013 Various Mono authors
Build started 9/8/2018 8:14:47 AM.
__________________________________________________
Project "/home/directhex/Projects/msbuildissue/msbuildissue.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Tool /usr/lib/mono/4.5/csc.exe execution started with arguments: /noconfig /out:obj/Debug/msbuildissue.exe code.cs obj/Debug/.NETFramework,Version=v4.6.1.AssemblyAttribute.cs /target:exe /nostdlib /reference:/usr/lib/mono/4.6.1-api/System.dll /reference:/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll /reference:/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll /reference:/usr/lib/mono/4.6.1-api/System.Core.dll /reference:/usr/lib/mono/4.6.1-api//mscorlib.dll
Microsoft (R) Visual C# Compiler version 2.8.2.62916 (2ad4aabc)
Copyright (C) Microsoft Corporation. All rights reserved.
Target DeployOutputFiles:
Copying file from '/home/directhex/Projects/msbuildissue/obj/Debug/msbuildissue.exe' to '/home/directhex/Projects/msbuildissue/bin/Debug/msbuildissue.exe'
Done building project "/home/directhex/Projects/msbuildissue/msbuildissue.csproj".
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.3920310
```
Those don't look like GAC paths, because they're not: they're the paths specified in the pkg-config file:
```
directhex@bionicvm:~$ cat /usr/lib/pkgconfig/gtk-sharp-2.0.pc
prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
gapidir=${prefix}/share/gapi-2.0
Name: Gtk#
Description: Gtk# - GNOME .NET Binding
Version: 2.12.45
Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml
Libs: -r:${libdir}/cli/pango-sharp-2.0/pango-sharp.dll -r:${libdir}/cli/atk-sharp-2.0/atk-sharp.dll -r:${libdir}/cli/gdk-sharp-2.0/gdk-sharp.dll -r:${libdir}/cli/gtk-sharp-2.0/gtk-sharp.dll
Requires: glib-sharp-2.0
```
I'm not saying MSBuild should support XBuild's pkg-config extension (although that WOULD fix the issue, and it's right there in Mono.XBuild.Tasks ready for the grabbing). But one way or another, installing library X+1 should not completely break support for using library X.
HintPath "works", but is a dreadful solution, since the full HintPath is not consistent across operating systems - OSX, Ubuntu, Fedora, etc, all put the relevant files in different places. Which prevents cross-platform collaboration.
### Environment data
`msbuild /version` output:
```
directhex@bionicvm:~$ msbuild /version
Microsoft (R) Build Engine version 15.1.8.0 ( Wed Sep 5 19:27:37 UTC 2018) for Mono
Copyright (C) Microsoft Corporation. All rights reserved.
15.1.8.0
```
OS info:
Ubuntu 18.04, but really, it's not OS-specific.
If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
Any. But this is particularly frustrating in VS for Mac - you cannot develop a Gtk#2 application (like VS for Mac) if you install Gtk#3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.