Skip to content

Commit

Permalink
Bump to xamarin/monodroid@fb0d5021; StrongName Xamarin.Android.Build.…
Browse files Browse the repository at this point in the history
…Tasks (#6116)

Context: https://discord.com/channels/732297728826277939/732297837953679412/865316625950572554
Context: https://discord.com/channels/732297728826277939/732297837953679412/869307441601470484

Changes: http://github.com/xamarin/monodroid/compare/b359d3b43774ff031add3d7a4949483052957db3...fb0d502139bc222d4e9ad82f912b1c6f1d4ca34e

  * xamarin/monodroid@fb0d50213: StrongName Xamarin.Android.Build.Debugging.Tasks (#1214)
  * xamarin/monodroid@71ac9a81b: Bump to 4ea37883 (#1220)

Occasionally when:

 1. Building on Windows within Visual Studio, with
 2. "Legacy" Xamarin.Android installed, and
 3. A preview .NET for Android (net6.0 + Android) workload installed

the build may fail:

	C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\30.0.100-preview.6.62\tools\Xamarin.Android.Common.targets(512,7): error MSB4064: The "ManifestPlaceholders" parameter is not supported by the "GetAndroidPackageName" task loaded from assembly: Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null from the path: D:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll. Verify that the parameter exists on the task, the <UsingTask> points to the correct assembly, and it is a settable public instance property.
	C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\30.0.100-preview.6.62\tools\Xamarin.Android.Common.targets(509,3): error MSB4063: The "GetAndroidPackageName" task could not be initialized with its input parameters.

The root cause of the problem is that *both* "Legacy" Xamarin.Android
and .NET SDK for Android contain a non-strong-named
`Xamarin.Android.Build.Tasks.dll`, and if a Project Solution `.sln`
contains Projects `.csproj` which reference both SDKs, then
`Xamarin.Android.Build.Tasks.dll` will only be loaded *once*, which
will be incompatible with the other.  In the above error message,
the legacy `Xamarin.Android.Build.Tasks.dll` was loaded first,
causing the build to fail when trying to build the .NET SDK for Android
project.

There are three ways to solve this:

 1. Maintain API compatibility between Legacy & .NET 6+
 2. Use different assembly names between "Legacy" and .NET 6+, or
 3. [Strong-name][0] all MSBuild-related assemblies.

(1) is a non-starter; new or different functionality is introduced as
part of .NET SDK for Android.  The assemblies can't be API compatible.

We could solve via (2) by renaming the .NET SDK for Android assembly
to e.g. `Microsoft.Android.Build.Tasks.dll`, but this only delays the
problem; come .NET 7, we'll still have the same assembly name for two
different installation locations (.NET 6, .NET 7), and they won't be
compatible with each other.

Which leaves (3): we strong-name our MSBuild assemblies.
Strong-naming allows us to have different versions installed
"side by side" (Legacy and .net 6) in separate directories.
Strong-naming is the best solution to this issue.

A few notes though.

 1. `pdb2mdb.exe` is now ILRepacked into `Xamarin.Android.Build.Tasks`
    via [`ILRepack`][1], as it is not Strong-named.  See also 610ade7.

 2. The `Xamarin.Android.Build.Tasks.csproj` project itself is *NOT*
    StrongNamed. This is because `pdb2mdb.exe` is not either.
    We handle the StrongNaming via the `ILRepacker` target later in
    the build.  The end result is a Strong-named 
    `Xamarin.Android.Build.Tasks.dll`.

Co-authored-by: Jonathan Peppers <jonathan.peppers@gmail.com>

[0]: https://docs.microsoft.com/en-us/dotnet/standard/assembly/strong-named
[1]: https://www.nuget.org/packages/ILRepack/
  • Loading branch information
dellis1972 committed Aug 11, 2021
1 parent 77895e2 commit 2d81740
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xamarin/monodroid:main@b359d3b43774ff031add3d7a4949483052957db3
xamarin/monodroid:main@fb0d502139bc222d4e9ad82f912b1c6f1d4ca34e
mono/mono:2020-02@c633fe923832f0c3db3c4e6aa98e5592bf5a06e7
2 changes: 0 additions & 2 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@
<_MSBuildFiles Include="$(MSBuildSrcDir)\monodoc.dll" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\monodoc.pdb" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\MULTIDEX_JAR_LICENSE" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\pdb2mdb.exe" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\pdb2mdb.pdb" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\proguard\lib\proguard.jar"/>
<_MSBuildFiles Include="$(MSBuildSrcDir)\proguard\license.md" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\startup.aotprofile" />
Expand Down
12 changes: 5 additions & 7 deletions src/Xamarin.Android.Build.Tasks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyDescription ("")]
[assembly: AssemblyCopyright ("Copyright © Novell 2010-2011 / Xamarin 2011-2012")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible (false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid ("42bb9aea-f4d8-4b43-8956-8e1fee857697")]


[assembly: InternalsVisibleTo ("AndroidMSBuildTests")]
[assembly: InternalsVisibleTo ("Xamarin.Android.Build.Tests")]
[assembly: InternalsVisibleTo ("MSBuildDeviceIntegration")]
[assembly: InternalsVisibleTo ("Xamarin.Android.Build.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
[assembly: InternalsVisibleTo ("MSBuildDeviceIntegration, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ void CompareFilesIgnoreRuntimeInfoString (string file1, string file2)
var runtimeVersionRegex = new Regex (@"//\s*Runtime Version:.*");
content1 = runtimeVersionRegex.Replace (content1, Environment.NewLine);
content2 = runtimeVersionRegex.Replace (content2, Environment.NewLine);
var replaceText = "\t[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"Xamarin.Android.Build.Tasks\", \"1.0.0.0\")]";
var assemblyVersionRegex = new Regex (@"(.*)GeneratedCodeAttribute(.{2})Xamarin.Android.Build.Tasks(.*)");
content1 = assemblyVersionRegex.Replace (content1, replaceText);
content2 = assemblyVersionRegex.Replace (content2, replaceText);

using (var s1 = new MemoryStream (Encoding.UTF8.GetBytes (content1)))
using (var s2 = new MemoryStream (Encoding.UTF8.GetBytes (content2))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
<OutputPath>..\..\..\..\bin\Test$(Configuration)</OutputPath>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<Import Project="..\..\..\..\Configuration.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<ProjectGuid>{2DD1EE75-6D8D-4653-A800-0A24367F7F38}</ProjectGuid>
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="..\..\..\..\Configuration.props" />
<Import Project="..\..\..\..\external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\MSBuildReferences.projitems" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<AndroidGeneratedClassDirectory Condition=" '$(AndroidGeneratedClassDirectory)' == '' ">..\..\src\Mono.Android\obj\$(Configuration)\monoandroid10\android-$(AndroidLatestStablePlatformId)\mcw</AndroidGeneratedClassDirectory>
<NoWarn>8632</NoWarn>
<GenerateResxSource>true</GenerateResxSource>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@
<InputAssemblies Include="$(OutputPath)NuGet.Versioning.dll" />
<InputAssemblies Include="$(OutputPath)System.Collections.Immutable.dll" />
<InputAssemblies Include="$(OutputPath)System.Reflection.Metadata.dll" />
<InputAssemblies Include="$(OutputPath)pdb2mdb.exe" />
</ItemGroup>

<Target Name="ILRepacker"
Expand All @@ -329,6 +330,7 @@
<PropertyGroup>
<_NetstandardDir>@(_NetstandardPath)</_NetstandardDir>
<_ILRepackArgs>/out:&quot;$(MSBuildThisFileDirectory)$(IntermediateOutputPath)$(AssemblyName).dll&quot; /internalize</_ILRepackArgs>
<_ILRepackArgs>$(_ILRepackArgs) /keyfile:&quot;$(XamarinAndroidSourcePath)product.snk&quot;</_ILRepackArgs>
<_ILRepackArgs>$(_ILRepackArgs) &quot;$(MSBuildThisFileDirectory)$(IntermediateOutputPath)$(AssemblyName).dll&quot;</_ILRepackArgs>
<_ILRepackArgs>$(_ILRepackArgs) @(_InputAssembliesThatExist->'&quot;%(Identity)&quot;', ' ')</_ILRepackArgs>
<_ILRepackArgs>$(_ILRepackArgs) /lib:&quot;$(_NetstandardDir.TrimEnd('\'))&quot;</_ILRepackArgs> <!-- Path to netstandard.dll -->
Expand Down Expand Up @@ -405,4 +407,12 @@
<Target Name="_Remove32BitLinux" Condition="Exists ('$(OutputPath)lib32\libZipSharpNative.so')" AfterTargets="CopyFilesToOutputDirectory">
<Delete Files="$(OutputPath)lib32\libZipSharpNative.so" />
</Target>

<Target Name="_SetAssemblyVersion"
DependsOnTargets="GetXAVersionInfo"
BeforeTargets="GetAssemblyVersion">
<PropertyGroup>
<Version>$(ProductVersion).$(PackVersionCommitCount)</Version>
</PropertyGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(XAInstallPrefix)xbuild\Xamarin\Android</OutputPath>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Xamarin.Android.Cecil">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<RootNamespace>Xamarin.Android.Build.Tests</RootNamespace>
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
<OutputPath>..\..\bin\Test$(Configuration)\MSBuildDeviceIntegration\</OutputPath>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<Import Project="..\..\Configuration.props" />
Expand Down
4 changes: 3 additions & 1 deletion tools/vswhere/vswhere.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>Xamarin.Android.Tools.VSWhere</RootNamespace>
<AssemblyName>vswhere</AssemblyName>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<Import Project="..\..\Configuration.props" />
Expand Down
2 changes: 2 additions & 0 deletions tools/xabuild/xabuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<_MSBuildExtension Condition=" '$(OS)' == 'Windows_NT' ">exe</_MSBuildExtension>
<_MSBuildExtension Condition=" '$(OS)' != 'Windows_NT' ">dll</_MSBuildExtension>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="..\..\Configuration.props" />
<ItemGroup>
Expand Down

0 comments on commit 2d81740

Please sign in to comment.