Skip to content

Commit

Permalink
[build] Allow Assembly "vendorization" (#136)
Browse files Browse the repository at this point in the history
Context: ff73f92
Context: 061bcc2
Context: xamarin/XamarinVS#12550

Changing `$(Version)` with every commit is fun and all, but doesn't
solve all problems.  Commit ff73f92 works "nicely" for MSBuild tasks
via [`<UsingTask/>`][0].  It doesn't work as well for "normal"
assembly references in a "normal" AppDomain context, because
assemblies are [normally resolved][1] via "assembly base name", *not*
the full path name including directory.

Thus, given `Example.dll`:

	csc /out:Example.dll /r:Path/To/Xamarin.Android.Tools.AndroidSdk.dll

then when `Example.dll` is loaded, it will try to load
`Xamarin.Android.Tools.AndroidSdk` via a `Load-by-name` method, and
will load the first `Xamarin.Android.Tools.AndroidSdk.dll` loaded
into the `AppDomain`/`AssemblyLoadContext`, regardless of version.

There may not be a good way to control what that assembly *is*.

This causes grief with our peer IDE teams, as assembly versions are
still checked, but on mismatch an exception is thrown (!).

Commit 061bcc2 was an attempt to address this, but proved to be
incomplete.

Attempt to improve matters by introducing a "vendorization" protocol:

 1. Update `Directory.Build.props` to import
    "parent directory.override.props", so that a "parent checkout"
    can easily override MSBuild properties.

 2. Update the `*.csproj` files so that `$(AssemblyName)` is forced
    to start with `$(VendorPrefix)`, and end with `$(VendorSuffix)`.

This allows a parent checkout to set the `$(VendorPrefix)` and
`$(VendorSuffix)` properties, which will impact the assembly filenames
of all assemblies built in xamarin-android-tools.

[0]: https://docs.microsoft.com/en-us/visualstudio/msbuild/usingtask-element-msbuild?view=vs-2019
[1]: https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/loading-managed
  • Loading branch information
jonpryor authored Sep 27, 2021
1 parent 061bcc2 commit 34e98e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
</PropertyGroup>
<Import
Project="$(MSBuildThisFileDirectory)Configuration.Override.props"
Condition=" Exists('$(MSBuildThisFileDirectory)Configuration.Override.props') "
/>
<Import
Project="$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props"
Condition=" Exists('$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props') "
/>
<PropertyGroup>
<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">obj\</BaseIntermediateOutputPath>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<UpdateXlfOnBuild Condition=" '$(RunningOnCI)' != 'true' ">true</UpdateXlfOnBuild>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyName>$(VendorPrefix)Microsoft.Android.Build.BaseTasks$(VendorSuffix)</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Description>Xamarin tools for interacting with the Android SDK.</Description>
<Copyright>Copyright © Xamarin 2011-2016</Copyright>
<PackageTags>Xamarin;Xamarin.Android</PackageTags>
<AssemblyName>$(VendorPrefix)Xamarin.Android.Tools.AndroidSdk$(VendorSuffix)</AssemblyName>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -38,7 +39,7 @@
</ItemGroup>

<ItemGroup>
<FilesToSign Include="$(OutDir)\Xamarin.Android.Tools.AndroidSdk.dll">
<FilesToSign Include="$(OutDir)\$(AssemblyName).dll">
<Authenticode>Microsoft400</Authenticode>
</FilesToSign>
</ItemGroup>
Expand Down

0 comments on commit 34e98e2

Please sign in to comment.