|
3 | 3 | using System.IO;
|
4 | 4 | using System.Linq;
|
5 | 5 | using System.Runtime.InteropServices;
|
6 |
| -using Xamarin.Android.Tools.VSWhere; |
| 6 | +using Xamarin.Android.Tools; |
7 | 7 |
|
8 | 8 | namespace Xamarin.ProjectTools
|
9 | 9 | {
|
@@ -47,69 +47,40 @@ public static bool IsLinux {
|
47 | 47 | }
|
48 | 48 | }
|
49 | 49 |
|
50 |
| - static readonly string LocalMonoAndroidToolsDirectory = Path.Combine (XABuildPaths.PrefixDirectory, "lib", "xamarin.android", "xbuild", "Xamarin", "Android"); |
51 |
| - |
52 |
| - public static readonly string MacOSInstallationRoot = "/Library/Frameworks/Xamarin.Android.framework/Versions/Current"; |
53 |
| - |
54 |
| - static VisualStudioInstance visualStudioInstance; |
55 |
| - public static VisualStudioInstance GetVisualStudioInstance () |
56 |
| - { |
57 |
| - //We should cache and reuse this value, so we don't run vswhere.exe so much |
58 |
| - if (visualStudioInstance != null && !string.IsNullOrEmpty (visualStudioInstance.VisualStudioRootPath)) |
59 |
| - return visualStudioInstance; |
60 |
| - |
61 |
| - return visualStudioInstance = MSBuildLocator.QueryLatest (); |
62 |
| - } |
63 |
| - |
64 | 50 | /// <summary>
|
65 |
| - /// The MonoAndroid framework (and other reference assemblies) directory within a local build tree. Contains v1.0, v9.0, etc, |
66 |
| - /// e.g. xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid.<br/> |
| 51 | + /// The MonoAndroid reference assemblies directory within a local build tree, e.g. bin/Debug/lib/packs/Microsoft.Android.Ref.34/34.99.0/ref/net8.0/<br/> |
67 | 52 | /// If a local build tree can not be found, or if it is empty, this will return the system installation location instead:<br/>
|
68 |
| - /// Windows: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid <br/> |
69 |
| - /// macOS: Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xamarin.android/xbuild-frameworks/MonoAndroid |
| 53 | + /// bin/Debug/dotnet/packs/Microsoft.Android.Ref.34/$(Latest)/ref/net$(Latest)/ |
70 | 54 | /// </summary>
|
71 | 55 | public static string MonoAndroidFrameworkDirectory {
|
72 | 56 | get {
|
73 |
| - var frameworkLibDir = Path.Combine (XABuildPaths.PrefixDirectory, "lib", "xamarin.android", "xbuild-frameworks", "MonoAndroid"); |
74 |
| - if (Directory.Exists (frameworkLibDir) && Directory.EnumerateDirectories (frameworkLibDir, "v*", SearchOption.TopDirectoryOnly).Any ()) |
75 |
| - return frameworkLibDir; |
76 |
| - |
77 |
| - if (IsWindows) { |
78 |
| - VisualStudioInstance vs = GetVisualStudioInstance (); |
79 |
| - return Path.Combine (vs.VisualStudioRootPath, "Common7", "IDE", "ReferenceAssemblies", "Microsoft", "Framework", "MonoAndroid"); |
80 |
| - } else { |
81 |
| - return Path.Combine (MacOSInstallationRoot, "lib", "xamarin.android", "xbuild-frameworks", "MonoAndroid"); |
| 57 | + var rootRefDir = Directory.GetDirectories (Path.Combine (DotNetPreviewPacksDirectory, $"Microsoft.Android.Ref.{XABuildConfig.AndroidDefaultTargetDotnetApiLevel}")).LastOrDefault (); |
| 58 | + if (!Directory.Exists (rootRefDir)) { |
| 59 | + throw new DirectoryNotFoundException ($"Unable to locate Microsoft.Android.Ref."); |
82 | 60 | }
|
| 61 | + |
| 62 | + var maDll = Directory.GetFiles (rootRefDir, "Mono.Android.dll", SearchOption.AllDirectories).LastOrDefault (); |
| 63 | + var refDir = Path.GetDirectoryName(maDll); |
| 64 | + if (!Directory.Exists (refDir)) { |
| 65 | + throw new DirectoryNotFoundException ($"Unable to locate Mono.Android.dll inside Microsoft.Android.Ref."); |
| 66 | + } |
| 67 | + |
| 68 | + return refDir; |
83 | 69 | }
|
84 | 70 | }
|
85 | 71 |
|
86 | 72 | /// <summary>
|
87 |
| - /// The MonoAndroidTools directory within a local build tree, e.g. xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android.<br/> |
88 |
| - /// If a local build tree can not be found, or if it is empty, this will return the system installation or .NET sandbox location instead:<br/> |
89 |
| - /// Windows: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android <br/> |
90 |
| - /// macOS: /Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xamarin.android/xbuild/Xamarin/Android<br/> |
91 |
| - /// Windows (dotnet): bin\Debug\dotnet\packs\Microsoft.Android.Sdk.Windows\$(Latest)\tools<br/> |
92 |
| - /// macOS (dotnet): bin/Debug/dotnet/packs/Microsoft.Android.Sdk.Darwin/$(Latest)/tools |
| 73 | + /// The MonoAndroidTools directory within a local build tree, e.g. bin/Debug/lib/packs/Microsoft.Android.Sdk.Darwin/34.99.0/tools/<br/> |
| 74 | + /// If a local build tree can not be found, or if it is empty, this will return the .NET sandbox location instead:<br/> |
| 75 | + /// Windows: bin\Debug\dotnet\packs\Microsoft.Android.Sdk.Windows\$(Latest)\tools<br/> |
| 76 | + /// macOS: bin/Debug/dotnet/packs/Microsoft.Android.Sdk.Darwin/$(Latest)/tools |
93 | 77 | /// </summary>
|
94 | 78 | public static string AndroidMSBuildDirectory {
|
95 | 79 | get {
|
96 |
| - if (Builder.UseDotNet) { |
97 |
| - if (!Directory.Exists (DotNetPreviewAndroidSdkDirectory)) { |
98 |
| - throw new DirectoryNotFoundException ($"Unable to locate a Microsoft.Android.Sdk in either '{DefaultPacksDir}' or '{LocalPacksDir}'."); |
99 |
| - } |
100 |
| - return Path.Combine (DotNetPreviewAndroidSdkDirectory, "tools"); |
101 |
| - } |
102 |
| - |
103 |
| - if (UseLocalBuildOutput) { |
104 |
| - return LocalMonoAndroidToolsDirectory; |
105 |
| - } else { |
106 |
| - if (IsWindows) { |
107 |
| - VisualStudioInstance vs = GetVisualStudioInstance (); |
108 |
| - return Path.Combine (vs.VisualStudioRootPath, "MSBuild", "Xamarin", "Android"); |
109 |
| - } else { |
110 |
| - return Path.Combine (MacOSInstallationRoot, "lib", "xamarin.android", "xbuild", "Xamarin", "Android"); |
111 |
| - } |
| 80 | + if (!Directory.Exists (DotNetPreviewAndroidSdkDirectory)) { |
| 81 | + throw new DirectoryNotFoundException ($"Unable to locate a Microsoft.Android.Sdk in either '{DefaultPacksDir}' or '{LocalPacksDir}'."); |
112 | 82 | }
|
| 83 | + return Path.Combine (DotNetPreviewAndroidSdkDirectory, "tools"); |
113 | 84 | }
|
114 | 85 | }
|
115 | 86 |
|
@@ -167,12 +138,12 @@ orderby version descending
|
167 | 138 |
|
168 | 139 | /// <summary>
|
169 | 140 | /// Tests will attempt to run against local build output directories by default,
|
170 |
| - /// and fall back to `dotnet/packs` or a legacy system install location if a local build does not exist. |
| 141 | + /// and fall back to `dotnet/packs` if a local build does not exist. |
171 | 142 | /// This will always return false for our tests running in CI.
|
172 | 143 | /// </summary>
|
173 | 144 | public static bool UseLocalBuildOutput {
|
174 | 145 | get {
|
175 |
| - var msbuildDir = Builder.UseDotNet ? Path.Combine (LocalDotNetAndroidSdkDirectory, "tools") : LocalMonoAndroidToolsDirectory; |
| 146 | + var msbuildDir = Path.Combine (LocalDotNetAndroidSdkDirectory, "tools"); |
176 | 147 | return Directory.Exists (msbuildDir) && File.Exists (Path.Combine (msbuildDir, "Xamarin.Android.Build.Tasks.dll"));
|
177 | 148 | }
|
178 | 149 | }
|
|
0 commit comments