Skip to content

Conversation

@jonathanpeppers
Copy link
Member

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.

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.
@jonpryor
Copy link
Contributor

I'm not sure I understand how this change will fix the MSB3248 error. How does adding the @(Reference) fix the error?

@radical
Copy link
Member

radical commented Jul 18, 2018

Without this explicit reference, does xabuild.exe end up with a reference to SRM at all? Is this just to get a local copy of SRM?

@jonathanpeppers
Copy link
Member Author

I installed this Mono: https://download.mono-project.com/archive/5.14.0/macos-10-universal/MonoFramework-MDK-5.14.0.167.macos10.xamarin.universal.pkg

And I could get the failure by just running:

bin/Debug/bin/xabuild Xamarin.Android-Tests.sln

And the error is:

xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2608,3):
    error MSB3248: Parameter "AssemblyFiles" has invalid value "xamarin-android/bin/TestDebug/Mono.Android-Tests.dll". Could not load file or assembly 'System.Reflection.Metadata, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

The offending MSBuild target looks like it is here: https://github.com/xamarin/xamarin-android/blob/5995f0c63943bacb807100785b3c85697d258f46/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L2619

After adding the change in this PR, it fixes it? Not sure why... The existence of the SRM assembly in bin/Debug/bin appears to fix the problem even though xabuild.exe doesn't use it directly.

@jonpryor
Copy link
Contributor

After adding the change in this PR, it fixes it? Not sure why...

(Insert hysterical laughing here.)

@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Jul 19, 2018

@jonpryor here are two logs: logs.zip

Plaintext logs (can't read without newer Mono apparently):
logs-plaintext.zip

Only difference in the one that works is that I built xabuild.csproj with this change.

@radical
Copy link
Member

radical commented Jul 19, 2018

Could you check whether SRM is present anywhere under the msbuild bin dir on windows?

@jonathanpeppers
Copy link
Member Author

@radical here is what I have for 15.7.5

> ls -File 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin'
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/12/2018   2:07 PM           3474 AssemblyFolders.config
-a----        7/12/2018   2:07 PM         236712 FileTracker32.dll
-a----        7/12/2018   2:07 PM         300704 FileTracker64.dll
-a----        7/12/2018   2:07 PM          98448 Microsoft.Build.Conversion.Core.dll
-a----        7/12/2018   2:07 PM        1726096 Microsoft.Build.dll
-a----        7/12/2018   2:07 PM         661648 Microsoft.Build.Engine.dll
-a----        7/12/2018   2:07 PM         118440 Microsoft.Build.Framework.dll
-a----        7/12/2018   2:07 PM        1260712 Microsoft.Build.Tasks.Core.dll
-a----        7/12/2018   2:07 PM         375440 Microsoft.Build.Utilities.Core.dll
-a----        7/12/2018   2:07 PM          10602 Microsoft.Common.CrossTargeting.targets
-a----        7/12/2018   2:07 PM         315838 Microsoft.Common.CurrentVersion.targets
-a----        7/12/2018   2:07 PM           6541 Microsoft.Common.overridetasks
-a----        7/12/2018   2:07 PM          14391 Microsoft.Common.targets
-a----        7/12/2018   2:07 PM          37813 Microsoft.Common.tasks
-a----        7/12/2018   2:07 PM           1349 Microsoft.CSharp.CrossTargeting.targets
-a----        7/12/2018   2:07 PM          21387 Microsoft.CSharp.CurrentVersion.targets
-a----        7/12/2018   2:07 PM          18932 Microsoft.CSharp.targets
-a----        7/12/2018   2:07 PM            918 Microsoft.Data.Entity.targets
-a----        7/12/2018   2:07 PM          12111 Microsoft.NetFramework.CurrentVersion.props
-a----        7/12/2018   2:07 PM           9811 Microsoft.NetFramework.CurrentVersion.targets
-a----        7/12/2018   2:07 PM           2400 Microsoft.NetFramework.props
-a----        7/12/2018   2:07 PM           6521 Microsoft.NetFramework.targets
-a----        7/12/2018   2:07 PM            920 Microsoft.ServiceModel.targets
-a----        7/12/2018   2:07 PM           1389 Microsoft.VisualBasic.CrossTargeting.targets
-a----        7/12/2018   2:07 PM          22005 Microsoft.VisualBasic.CurrentVersion.targets
-a----        7/12/2018   2:07 PM          19101 Microsoft.VisualBasic.targets
-a----        7/12/2018   2:07 PM            906 Microsoft.WinFx.targets
-a----        7/12/2018   2:07 PM           1510 Microsoft.WorkflowBuildExtensions.targets
-a----        7/12/2018   2:07 PM           1316 Microsoft.Xaml.targets
-a----        7/12/2018   2:07 PM         308888 MSBuild.exe
-a----        7/12/2018   2:07 PM           8989 MSBuild.exe.config
-a----        7/12/2018   2:07 PM            732 MSBuild.rsp
-a----        7/12/2018   2:07 PM         219320 MSBuildTaskHost.exe
-a----        7/12/2018   2:07 PM           1132 MSBuildTaskHost.exe.config
-a----        7/12/2018   2:07 PM         244432 System.Collections.Immutable.dll
-a----        7/12/2018   2:07 PM         111984 System.IO.Compression.dll
-a----        7/12/2018   2:07 PM          33256 System.Runtime.InteropServices.RuntimeInformation.dll
-a----        7/12/2018   2:07 PM         182504 System.Threading.Tasks.Dataflow.dll
-a----        7/12/2018   2:07 PM         174696 Tracker.exe
-a----        7/12/2018   2:07 PM            822 Workflow.targets
-a----        7/12/2018   2:07 PM            834 Workflow.VisualBasic.targets

And then 15.8 P5 (appears the same):

ls -File 'C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin'
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/19/2018  12:21 PM           3474 AssemblyFolders.config
-a----        7/19/2018  12:21 PM         238104 FileTracker32.dll
-a----        7/19/2018  12:21 PM         302104 FileTracker64.dll
-a----        7/19/2018  12:21 PM          98960 Microsoft.Build.Conversion.Core.dll
-a----        7/19/2018  12:21 PM        1741968 Microsoft.Build.dll
-a----        7/19/2018  12:21 PM         662160 Microsoft.Build.Engine.dll
-a----        7/19/2018  12:21 PM         129672 Microsoft.Build.Framework.dll
-a----        7/19/2018  12:21 PM        1325200 Microsoft.Build.Tasks.Core.dll
-a----        7/19/2018  12:21 PM         385672 Microsoft.Build.Utilities.Core.dll
-a----        7/19/2018  12:21 PM          10602 Microsoft.Common.CrossTargeting.targets
-a----        7/19/2018  12:21 PM         319085 Microsoft.Common.CurrentVersion.targets
-a----        7/19/2018  12:21 PM           6541 Microsoft.Common.overridetasks
-a----        7/19/2018  12:21 PM          14391 Microsoft.Common.targets
-a----        7/19/2018  12:21 PM          39041 Microsoft.Common.tasks
-a----        7/19/2018  12:21 PM           1349 Microsoft.CSharp.CrossTargeting.targets
-a----        7/19/2018  12:21 PM          21387 Microsoft.CSharp.CurrentVersion.targets
-a----        7/19/2018  12:21 PM          18932 Microsoft.CSharp.targets
-a----        7/19/2018  12:21 PM            918 Microsoft.Data.Entity.targets
-a----        7/19/2018  12:21 PM          12216 Microsoft.NetFramework.CurrentVersion.props
-a----        7/19/2018  12:21 PM           9811 Microsoft.NetFramework.CurrentVersion.targets
-a----        7/19/2018  12:21 PM           2400 Microsoft.NetFramework.props
-a----        7/19/2018  12:21 PM           6521 Microsoft.NetFramework.targets
-a----        7/19/2018  12:21 PM            920 Microsoft.ServiceModel.targets
-a----        7/19/2018  12:21 PM           1389 Microsoft.VisualBasic.CrossTargeting.targets
-a----        7/19/2018  12:21 PM          22005 Microsoft.VisualBasic.CurrentVersion.targets
-a----        7/19/2018  12:21 PM          19101 Microsoft.VisualBasic.targets
-a----        7/19/2018  12:21 PM            906 Microsoft.WinFx.targets
-a----        7/19/2018  12:21 PM           1510 Microsoft.WorkflowBuildExtensions.targets
-a----        7/19/2018  12:21 PM           1316 Microsoft.Xaml.targets
-a----        7/19/2018  12:21 PM         317592 MSBuild.exe
-a----        7/19/2018  12:21 PM           8989 MSBuild.exe.config
-a----        7/19/2018  12:21 PM            732 MSBuild.rsp
-a----        7/19/2018  12:21 PM         223408 MSBuildTaskHost.exe
-a----        7/19/2018  12:21 PM           1132 MSBuildTaskHost.exe.config
-a----        7/19/2018  12:21 PM         358536 System.Collections.Immutable.dll
-a----        7/19/2018  12:21 PM         111984 System.IO.Compression.dll
-a----        7/19/2018  12:21 PM          33256 System.Runtime.InteropServices.RuntimeInformation.dll
-a----        7/19/2018  12:21 PM         182504 System.Threading.Tasks.Dataflow.dll
-a----        7/19/2018  12:21 PM         176144 Tracker.exe
-a----        7/19/2018  12:21 PM            822 Workflow.targets
-a----        7/19/2018  12:21 PM            834 Workflow.VisualBasic.targets

@radical
Copy link
Member

radical commented Jul 19, 2018

@jonathanpeppers ah, that makes sense. SRM is used on !windows like coreclr and mono to allow reading metadata from assemblies without actually loading them. And for windows they use windows APIs. So, what is referencing SRM then? Do you have any of Microsoft.Build* assemblies being local copied, even after #1975? Try with a build from #1975 . That hopefully should work, because mono's msbuild assemblies would be referencing SRM (correctly), so removing those and having the assembly resolver using the windows msbuild assemblies, should remove the need for SRM completely.

@jonpryor jonpryor merged commit 43362f9 into dotnet:master Aug 2, 2018
jonpryor pushed a commit that referenced this pull request Aug 3, 2018
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.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants