Skip to content

Commit 34e98e2

Browse files
authored
[build] Allow Assembly "vendorization" (#136)
Context: ff73f92 Context: 061bcc2 Context: https://github.com/xamarin/XamarinVS/pull/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
1 parent 061bcc2 commit 34e98e2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
</PropertyGroup>
7+
<Import
8+
Project="$(MSBuildThisFileDirectory)Configuration.Override.props"
9+
Condition=" Exists('$(MSBuildThisFileDirectory)Configuration.Override.props') "
10+
/>
11+
<Import
12+
Project="$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props"
13+
Condition=" Exists('$([System.IO.Path]::GetDirectoryName($(MSBuildThisFileDirectory))).override.props') "
14+
/>
715
<PropertyGroup>
816
<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">obj\</BaseIntermediateOutputPath>
917
</PropertyGroup>

src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<UpdateXlfOnBuild Condition=" '$(RunningOnCI)' != 'true' ">true</UpdateXlfOnBuild>
1212
<SignAssembly>true</SignAssembly>
1313
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
14+
<AssemblyName>$(VendorPrefix)Microsoft.Android.Build.BaseTasks$(VendorSuffix)</AssemblyName>
1415
</PropertyGroup>
1516

1617
<ItemGroup>

src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<Description>Xamarin tools for interacting with the Android SDK.</Description>
1515
<Copyright>Copyright © Xamarin 2011-2016</Copyright>
1616
<PackageTags>Xamarin;Xamarin.Android</PackageTags>
17+
<AssemblyName>$(VendorPrefix)Xamarin.Android.Tools.AndroidSdk$(VendorSuffix)</AssemblyName>
1718
</PropertyGroup>
1819

1920
<PropertyGroup>
@@ -38,7 +39,7 @@
3839
</ItemGroup>
3940

4041
<ItemGroup>
41-
<FilesToSign Include="$(OutDir)\Xamarin.Android.Tools.AndroidSdk.dll">
42+
<FilesToSign Include="$(OutDir)\$(AssemblyName).dll">
4243
<Authenticode>Microsoft400</Authenticode>
4344
</FilesToSign>
4445
</ItemGroup>

0 commit comments

Comments
 (0)