From 3bba98e83944259c0410793e314b778bc0e9c79f Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 14 Jun 2016 10:48:32 -0400 Subject: [PATCH] [build] Set $(TargetFrameworkRootPath) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @atsushieno and I are trying to figure out why `src/Mono.Posix` builds for me on OS X but fails for him in a (relatively) clean Linux environment: CSC: error CS0518: The predefined type `System.Object' is not defined or imported `System.Object` couldn't be found because `System.Runtime.dll` wasn't being provided to the compiler. Further investigation shows that the reason it built on OS X was because OS X had a pre-existing system Xamarin.Android install, which was being used to resolve framework directories: # Works on OS X: # Note: Mono.framework/External/xbuild-frameworks/MonoAndroid is a symlink # into Xamarin.Android.framework, i.e. the system Xamarin.Android install Task "GetReferenceAssemblyPaths" Using task GetReferenceAssemblyPaths from Microsoft.Build.Tasks.GetReferenceAssemblyPaths, Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Looking for framework 'MonoAndroid,Version=v1.0' in root path '/Library/Frameworks/Mono.framework/External/xbuild-frameworks' Found framework definition list '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/RedistList/FrameworkList.xml' for framework 'MonoAndroid,Version=v1.0' Done executing task "GetReferenceAssemblyPaths" # Fails on Linux: Target _GetReferenceAssemblyPaths: warning : Unable to find framework corresponding to the target framework moniker 'MonoAndroid,Version=v1.0'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior. Turns Outâ„¢, the error can be reproduced on OS X by "removing" the system Xamarin.Android install: $ cd /Library/Frameworks/Mono.framework/External/xbuild-frameworks $ sudo mv MonoAndroid _MonoAndroid Task "GetReferenceAssemblyPaths" Using task GetReferenceAssemblyPaths from Microsoft.Build.Tasks.GetReferenceAssemblyPaths, Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Looking for framework 'MonoAndroid,Version=v6.0' in root path '/Library/Frameworks/Mono.framework/External/xbuild-frameworks' Unable to find framework definition file '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v6.0/RedistList/FrameworkList.xml' for Target Framework Moniker 'MonoAndroid,Version=v6.0' Looking for framework 'MonoAndroid,Version=v6.0' in root path '/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/../xbuild-frameworks' Unable to find framework definition file '/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/../xbuild-frameworks/MonoAndroid/v6.0/RedistList/FrameworkList.xml' for Target Framework Moniker 'MonoAndroid,Version=v6.0' .../Microsoft.Common.targets: warning : Unable to find framework corresponding to the target framework moniker 'MonoAndroid,Version=v6.0'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior. Done executing task "GetReferenceAssemblyPaths" (Not sure why it's looking for *v6.0*`, but it can't find the framework at all, so that's consistent with Linux.) The fix is to set the `$(TargetFrameworkRootPath)` MSBuild property, which is provided to the [`GetReferenceAssemblyPaths.RootPath`][0] property, and allows controlling which locations are searched for frameworks. Unfortunately, `$(TargetFrameworkRootPath)` needs to be set to `bin\$(Configuration)\lib\xbuild-frameworks`, which means `$(Configuration)` needs to be set *before* `$(TargetFrameworkRootPath)` is set. Furthermore, since we want to set `$(TargetFrameworkRootPath)` in `Configuration.props`, this means that we need to audit all locations which import `Configuration.props` to ensure that `$(Configuration)` is set before the import. Add `$(TargetFrameworkRootPath)` to `Configuration.props`, and audit all uses of `Configuration.props` to ensure `$(Configuration) is set. [0]: https://msdn.microsoft.com/en-us/library/microsoft.build.tasks.getreferenceassemblypaths.rootpath.aspx --- Configuration.props | 4 ++++ src/Mono.Android/Test/Mono.Android-Tests.csproj | 6 ++++-- .../Xamarin.Android.Build.Tests.csproj | 2 +- .../Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj | 2 +- .../Xamarin.Android.Build.Tasks.csproj | 2 +- tools/api-xml-adjuster/api-xml-adjuster.csproj | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Configuration.props b/Configuration.props index f71adb1f5ce..d7bad9fb4b3 100644 --- a/Configuration.props +++ b/Configuration.props @@ -1,5 +1,8 @@ + cc c++ mono + $(MSBuildThisFileDirectory)bin\$(Configuration)\lib\xbuild-frameworks $(HOMEDRIVE)$(HOMEPATH) 23 v6.0 diff --git a/src/Mono.Android/Test/Mono.Android-Tests.csproj b/src/Mono.Android/Test/Mono.Android-Tests.csproj index 03290e0d4cb..ff3df28aa25 100644 --- a/src/Mono.Android/Test/Mono.Android-Tests.csproj +++ b/src/Mono.Android/Test/Mono.Android-Tests.csproj @@ -1,6 +1,5 @@ - Debug AnyCPU @@ -17,7 +16,10 @@ Assets Mono.Android-Tests Properties\AndroidManifest.xml - v4.2 + + + + $(AndroidFrameworkVersion) true diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj index 006f2a23655..d893067139f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj @@ -1,6 +1,5 @@ - Debug AnyCPU @@ -10,6 +9,7 @@ Xamarin.Android.Build.Tests v4.5 + true full diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj index 20e8dcaa48c..e8c43544796 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj @@ -1,6 +1,5 @@ - Debug AnyCPU @@ -10,6 +9,7 @@ Xamarin.ProjectTools v4.5 + true full diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 773eeb3b2a9..fb1b9b8cac7 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -2,7 +2,6 @@ - Debug AnyCPU @@ -14,6 +13,7 @@ 512 v4.5 + True full diff --git a/tools/api-xml-adjuster/api-xml-adjuster.csproj b/tools/api-xml-adjuster/api-xml-adjuster.csproj index e052317491b..308b3c58fbe 100644 --- a/tools/api-xml-adjuster/api-xml-adjuster.csproj +++ b/tools/api-xml-adjuster/api-xml-adjuster.csproj @@ -9,6 +9,7 @@ api-xml-adjuster v4.5 + true full