Skip to content

Commit

Permalink
[msbuild] Sign Xamarin.iOS.Tasks.dll and Xamarin.Mac.Tasks.dll. Fixes #…
Browse files Browse the repository at this point in the history
…9835. (#12831)

We need to strongname our MSBuild assemblies, so that different versions
can be loaded side-by-side (one example being having both a legacy and a
.NET project in the same solution).

This required setting a version for Xamarin.iOS.Tasks.dll and
Xamarin.Mac.Tasks.dll, otherwise strong-naming won't work properly (all
versions of an assembly would have the same identity).

Also sign the corresponding test assemblies, since they poke into the
internals of the task assemblies.

Fixes #9835.
  • Loading branch information
rolfbjarne authored Sep 28, 2021
1 parent b20ca55 commit 7dc2d9a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 4 deletions.
1 change: 1 addition & 0 deletions msbuild/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Versions.*.g.cs
.failed-stamp
.build-stamp
.stamp-test-xml
Expand Down
5 changes: 4 additions & 1 deletion msbuild/ILMerge.targets
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
<LibDir Include="@(ReferenceCopyLocalDirs -&gt; Distinct())" />
</ItemGroup>
<PropertyGroup>
<ILRepackArgs Condition="'$(AssemblyOriginatorKeyFile)' != ''">/keyfile:"$(AssemblyOriginatorKeyFile)"</ILRepackArgs>
<AbsoluteAssemblyOriginatorKeyFile Condition="'$(AssemblyOriginatorKeyFile)' != ''">$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine('$(MSBuildProjectDirectory)','$(AssemblyOriginatorKeyFile)'))))</AbsoluteAssemblyOriginatorKeyFile>
<ILRepackArgs Condition="'$(AbsoluteAssemblyOriginatorKeyFile)' != ''">/keyfile:"$(AbsoluteAssemblyOriginatorKeyFile)" /delaysign</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) @(LibDir -&gt; '/lib:"%(Identity)."', ' ')</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) /out:"@(IntermediateAssembly -&gt; '%(FullPath)')"</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) "@(IntermediateAssembly -&gt; '%(FullPath)')"</ILRepackArgs>
Expand All @@ -80,6 +81,8 @@
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput" />
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
</Exec>
<!-- ILRepack.MSBuild.Task fails when trying to sign the assembly, so instead just delay-sign and use 'sn' to sign after ILRepack.MSBuild.Task is done (ILRepack works fine, but we can't use it for other reasons, mentioned above) -->
<Exec Command="sn -R &quot;@(IntermediateAssembly -&gt; '%(FullPath)')&quot; ../../product.snk" Condition="'$(AbsoluteAssemblyOriginatorKeyFile)' != '' And '$(ExitCode)' == '0'" />
<Message Importance="high" Text="$(ILRepackOutput)" Condition="'$(ExitCode)' != '0'" />
<Delete Files="$(IntermediateOutputPath)ilrepack.txt" Condition="'$(ExitCode)' != '0'" />
<Touch AlwaysCreate="true" Files="$(IntermediateOutputPath)ilrepack.txt" Condition="'$(ExitCode)' == '0'" />
Expand Down
17 changes: 17 additions & 0 deletions msbuild/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,23 @@ clean-local::
git clean -xfdq
cd $(XAMARIN_MACDEV_PATH) && git clean -xfdq

# We use the legacy Xamarin versions for the .NET assemblies as well.
Versions.mac.g.cs: Makefile $(TOP)/Make.config.inc
$(Q) printf "static class VersionConstants {\\n" > $@.tmp
$(Q) printf "\\tpublic const string XamarinMacVersion = \"$(MAC_PACKAGE_VERSION)\";\\n" >> $@.tmp
$(Q) printf "\\tpublic const string NuGetPrereleaseIdentifier = \"$(NUGET_PRERELEASE_IDENTIFIER)\";\\n" >> $@.tmp
$(Q) printf "\\tpublic const string NuGetBuildMetadata = \"$(NUGET_BUILD_METADATA)\";\\n" >> $@.tmp
$(Q) printf "}\\n" >> $@.tmp
$(Q) mv $@.tmp $@

Versions.ios.g.cs: Makefile $(TOP)/Make.config.inc
$(Q) printf "static class VersionConstants {\\n" > $@.tmp
$(Q) printf "\\tpublic const string XamarinIOSVersion = \"$(IOS_PACKAGE_VERSION)\";\\n" >> $@.tmp
$(Q) printf "\\tpublic const string NuGetPrereleaseIdentifier = \"$(NUGET_PRERELEASE_IDENTIFIER)\";\\n" >> $@.tmp
$(Q) printf "\\tpublic const string NuGetBuildMetadata = \"$(NUGET_BUILD_METADATA)\";\\n" >> $@.tmp
$(Q) printf "}\\n" >> $@.tmp
$(Q) mv $@.tmp $@

dotnet:: $(DOTNET_TARGETS)

# make will automatically consider files created in chained implicit rules as temporary files, and delete them afterwards
Expand Down
13 changes: 13 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyCompanyAttribute ("Microsoft Corp.")]
[assembly: AssemblyFileVersionAttribute (VersionConstants.XamarinMacVersion)]
[assembly: AssemblyInformationalVersionAttribute (VersionConstants.XamarinMacVersion + "." + VersionConstants.NuGetPrereleaseIdentifier + "+" + VersionConstants.NuGetBuildMetadata)]
[assembly: AssemblyProductAttribute ("Xamarin.Mac.Tasks")]
[assembly: AssemblyTitleAttribute ("Xamarin.Mac.Tasks")]
[assembly: AssemblyVersionAttribute (VersionConstants.XamarinMacVersion)]

[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tasks.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
7 changes: 7 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Messaging.Build.Client" Version="$(MessagingVersion)" />
Expand All @@ -26,7 +28,12 @@
<None Include="../Xamarin.Shared/*.props">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Include="../Versions.mac.g.cs" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\ILMerge.targets" />

<Target Name="BuildGeneratedVersionsFile" Inputs="../../Make.config.inc;../Makefile" Outputs="../Versions.mac.g.cs" BeforeTargets="BeforeBuild">
<Exec Command="make -C .. Versions.mac.g.cs" />
</Target>
</Project>
3 changes: 2 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tasks.Tests")]
[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tasks.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]

13 changes: 11 additions & 2 deletions msbuild/Xamarin.iOS.Tasks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tasks.Tests")]
[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tests")]
[assembly: AssemblyCompanyAttribute ("Microsoft Corp.")]
[assembly: AssemblyFileVersionAttribute (VersionConstants.XamarinIOSVersion)]
[assembly: AssemblyInformationalVersionAttribute (VersionConstants.XamarinIOSVersion + "." + VersionConstants.NuGetPrereleaseIdentifier + "+" + VersionConstants.NuGetBuildMetadata)]
[assembly: AssemblyProductAttribute ("Xamarin.iOS.Tasks")]
[assembly: AssemblyTitleAttribute ("Xamarin.iOS.Tasks")]
[assembly: AssemblyVersionAttribute (VersionConstants.XamarinIOSVersion)]

[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tasks.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
[assembly: InternalsVisibleTo ("Xamarin.MacDev.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
7 changes: 7 additions & 0 deletions msbuild/Xamarin.iOS.Tasks/Xamarin.iOS.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IncludeMSBuildAssets Condition="'$(IncludeMSBuildAssets)' == ''">compile</IncludeMSBuildAssets>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<Import Project="..\..\eng\Versions.props" />
Expand Down Expand Up @@ -34,8 +36,13 @@
<ItemGroup>
<Folder Include="Model\" />
<Folder Include="Contracts\" />
<Compile Include="../Versions.ios.g.cs" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)..\ILMerge.targets" />

<Target Name="BuildGeneratedVersionsFile" Inputs="../../Make.config.inc;../Makefile" Outputs="../Versions.ios.g.cs" BeforeTargets="BeforeBuild">
<Exec Command="make -C .. Versions.ios.g.cs" />
</Target>

<!-- Replaces the ProtectedData assembly by the runtime implementation -->
<Target Name="CopyRuntimeAssemblies" BeforeTargets="ILRepack">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>
<LangVersion>latest</LangVersion>
<DefineConstants>$(DefineConstants);MSBUILD_TASKS</DefineConstants>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../../product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>
<LangVersion>latest</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../../product.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
Expand Down

3 comments on commit 7dc2d9a

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [CI Build] Tests passed on Build. ✅

Tests passed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (only version changes)

Packages generated

View packages

🎉 All 243 tests passed 🎉

Pipeline on Agent XAMBOT-1038.BigSur'
[msbuild] Sign Xamarin.iOS.Tasks.dll and Xamarin.Mac.Tasks.dll. Fixes #9835. (#12831)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[msbuild] Sign Xamarin.iOS.Tasks.dll and Xamarin.Mac.Tasks.dll. Fixes #9835. (#12831)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[msbuild] Sign Xamarin.iOS.Tasks.dll and Xamarin.Mac.Tasks.dll. Fixes #9835. (#12831)

Please sign in to comment.