From 34e98e2b65917d105169f868b5648f67e68b6784 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 27 Sep 2021 18:06:26 -0400 Subject: [PATCH] [build] Allow Assembly "vendorization" (#136) Context: ff73f925a399df523cd89a9b8b49849e63fe0411 Context: 061bcc2eb6e81b2ef7b26ec37315c0c636cf2093 Context: https://github.com/xamarin/XamarinVS/pull/12550 Changing `$(Version)` with every commit is fun and all, but doesn't solve all problems. Commit ff73f925 works "nicely" for MSBuild tasks via [``][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 061bcc2e 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 --- Directory.Build.props | 8 ++++++++ .../Microsoft.Android.Build.BaseTasks.csproj | 1 + .../Xamarin.Android.Tools.AndroidSdk.csproj | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 74fe6cf..d03b71f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,14 @@ Debug + + obj\ diff --git a/src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj b/src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj index 0a431c9..cc25bb5 100644 --- a/src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj +++ b/src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj @@ -11,6 +11,7 @@ true true ..\..\product.snk + $(VendorPrefix)Microsoft.Android.Build.BaseTasks$(VendorSuffix) diff --git a/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj b/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj index 3d1fee5..9500ed5 100644 --- a/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj +++ b/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj @@ -14,6 +14,7 @@ Xamarin tools for interacting with the Android SDK. Copyright © Xamarin 2011-2016 Xamarin;Xamarin.Android + $(VendorPrefix)Xamarin.Android.Tools.AndroidSdk$(VendorSuffix) @@ -38,7 +39,7 @@ - + Microsoft400