-
Notifications
You must be signed in to change notification settings - Fork 564
[xabuild] MSBuild assemblies should not "Copy Local" #1975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xabuild] MSBuild assemblies should not "Copy Local" #1975
Conversation
f52dddf to
9b643d6
Compare
|
@radical running into different issues on each platform now, but Windows seems worse to fix... Windows (I think) is hitting an issue related to Xamarin.Forms build tasks being strong named: However, the missing assembly is loaded earlier successfully: Does MSBuild also have a custom |
Context: dotnet#1975 In newer versions of Mono, `xabuild` is failing with: /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2126,5): error MSB3248: Parameter "AssemblyFiles" has invalid value "xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Or another example: Mono: The following assembly referenced from monodroid/external/xamarin-android/bin/Debug/bin/Microsoft.Build.Tasks.Core.dll could not be loaded: Assembly: System.Reflection.Metadata (assemblyref_index=7) Version: 1.3.0.0 Public Key: b03f5f7f11d50a3a Looking at copies of `System.Reflection.Metadata` in my Mono installation: $ find /Library/Frameworks/Mono.framework/ | grep System.Reflection.Metadata.dll$ /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/msbuild/15.0/bin/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/msbuild/15.0/bin/Roslyn/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/fsharp/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/4.5/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/4.5/dim/System.Reflection.Metadata.dll It appears that the Mono version of MSBuild has its own copy of `System.Reflection.Metadata.dll`. Referencing this MSBuild-specific assembly from `xabuild.csproj` on non-Windows platforms appears to solve the problem.
|
In VSMac we restrict the resolve hook to msbuild assemblies, see https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Projects.Formats.MSBuild/Main.cs#L111-L132 . Also, maybe you want to try
|
|
@radical I think I know why it's not working 😖 Watching |
9b643d6 to
7eabb49
Compare
Mono 2018-04 (or 5.14.x) has some changes to MSBuild assemblies that
cause the following failure when using `xabuild.exe`:
Mono: The following assembly referenced from monodroid/external/xamarin-android/bin/Debug/bin/Microsoft.Build.Tasks.Core.dll could not be loaded:
Assembly: System.Reflection.Metadata (assemblyref_index=7)
Version: 1.3.0.0
Public Key: b03f5f7f11d50a3a
Currently `xabuild.exe` is referencing various MSBuild assemblies that
get copied into `bin/$(Configuration)/bin` and shipped in the OSS zip.
This isn't exactly desirable, since we don't really want to ship these
assemblies... These assemblies are OS-specific (as far as I can tell),
I noticed that these assemblies coming from a zip built on macOS do
not work on Windows.
`xabuild.exe` does not need to reference any MSBuild assemblies, and
we can use reflection + custom assembly loading to load MSBuild. This
keeps `bin/Debug/bin` free of additional assemblies, and now only
contains a few files:
- xabuild
- xabuild.exe
- xabuild.exe.config
- xabuild.pdb
By using the `AppDomain.AssemblyResolve` event, we can add some code
to probe the MSBuild bin directory for assemblies. If not found, we
can return `null` and let the runtime do its default behavior.
7eabb49 to
846e359
Compare
Context: #1975 In newer versions of Mono, `xabuild` is failing with: /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2126,5): error MSB3248: Parameter "AssemblyFiles" has invalid value "xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Or another example: Mono: The following assembly referenced from monodroid/external/xamarin-android/bin/Debug/bin/Microsoft.Build.Tasks.Core.dll could not be loaded: Assembly: System.Reflection.Metadata (assemblyref_index=7) Version: 1.3.0.0 Public Key: b03f5f7f11d50a3a Looking at copies of `System.Reflection.Metadata` in my Mono installation: $ find /Library/Frameworks/Mono.framework/ | grep System.Reflection.Metadata.dll$ /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/msbuild/15.0/bin/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/msbuild/15.0/bin/Roslyn/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/fsharp/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/4.5/System.Reflection.Metadata.dll /Library/Frameworks/Mono.framework//Versions/5.12.0/lib/mono/4.5/dim/System.Reflection.Metadata.dll It appears that the Mono version of MSBuild has its own copy of `System.Reflection.Metadata.dll`. Referencing this MSBuild-specific assembly from `xabuild.csproj` on non-Windows platforms appears to solve the problem.
|
An update on the changes here, Xamarin.Forms has a task using Which, explains why this is happening Windows: a new |
|
I think what @jonathanpeppers meant was not really a new MSBuild.exe but a new app domain in the same process (please correct me if I'm wrong). And that is created for loading the |
|
Yeah I am not sure if the |
Context: #1975 Mono 2018-04 (or 5.14.x) has some changes to MSBuild assemblies that cause failures such as the following when using `xabuild.exe`: /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2126,5): error MSB3248: Parameter "AssemblyFiles" has invalid value "xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Mono: The following assembly referenced from monodroid/external/xamarin-android/bin/Debug/bin/Microsoft.Build.Tasks.Core.dll could not be loaded: Assembly: System.Reflection.Metadata (assemblyref_index=7) Version: 1.3.0.0 Public Key: b03f5f7f11d50a3a It appears that the Mono version of MSBuild has its own copy of `System.Reflection.Metadata.dll`. Referencing this MSBuild-specific assembly from `xabuild.csproj` on non-Windows platforms appears to fix the above errors.
|
Do we need this anymore? Can it be closed? |
|
I will revisit this later, if we can work around what Windows is doing I think it is ultimately better. What we have right now in our OSS zip file doesn't work when using a MacOS build on Windows, because it zips up MacOS assemblies for MSBuild. |
Context: #1975 Mono 2018-04 (or 5.14.x) has some changes to MSBuild assemblies that cause failures such as the following when using `xabuild.exe`: /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(2126,5): error MSB3248: Parameter "AssemblyFiles" has invalid value "xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Mono: The following assembly referenced from monodroid/external/xamarin-android/bin/Debug/bin/Microsoft.Build.Tasks.Core.dll could not be loaded: Assembly: System.Reflection.Metadata (assemblyref_index=7) Version: 1.3.0.0 Public Key: b03f5f7f11d50a3a It appears that the Mono version of MSBuild has its own copy of `System.Reflection.Metadata.dll`. Referencing this MSBuild-specific assembly from `xabuild.csproj` on non-Windows platforms appears to fix the above errors.

Mono 2018-04 (or 5.14.x) has some changes to MSBuild assemblies that
cause the following failure when using
xabuild.exe:Currently
xabuild.exeis referencing various MSBuild assemblies thatget copied into
bin/$(Configuration)/binand shipped in the OSS zip.This isn't exactly desirable, since we don't really want to ship these
assemblies... These assemblies are OS-specific (as far as I can tell),
I noticed that these assemblies coming from a zip built on macOS do
not work on Windows.
xabuild.exedoes not need to reference any MSBuild assemblies, andwe can use reflection + custom assembly loading to load MSBuild. This
keeps
bin/Debug/binfree of additional assemblies, and now onlycontains a few files:
By using the
AppDomain.AssemblyResolveevent, we can add some codeto probe the MSBuild bin directory for assemblies. If not found, we
can return
nulland let the runtime do its default behavior.