Skip to content

Commit b0bac43

Browse files
[build] create xamarin-android-tools.override.props
If you installed the `android` workload via: dotnet workload install android --skip-sign-check \ --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/net8.0.json \ --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json \ --source https://api.nuget.org/v3/index.json `dotnet new android` & `dotnet build` succeeds. But `MSBuild.exe` fails with: D:\src\dotnet-sdk-8.0.100-preview.6.23318.1-win-x64\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.6.323\tools\Xamarin.Android.EmbeddedResource.targets(39,5): error XARLP7028: System.IO.FileNotFoundException: Could not load file or assembly 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' or one of its dependencies. The system cannot find the file specified. File name: 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(IDictionary`2 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments, ICollection`1 proguardConfigFiles) at Xamarin.Android.Tasks.ResolveLibraryProjectImports.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. It turns out that for references to `libZipSharp.dll`: * `Microsoft.Android.Build.BaseTasks.dll` references 2.1.0.0 * `Xamarin.Android.Build.Tasks.dll` references 3.0.0.0 However, this appears to already be solved in the 34.0.0-preview.6.355 version of the `android` workload. It is broken in `34.0.0-preview.6.323`. In that time window, we updated `$(LibZipSharpVersion)` in xamarin/xamarin-android, but not yet bumped to the latest xamarin/xamarin-android-tools: f1d5918 To solve this issue, we can use the extension points we added to: dotnet/android-tools@34e98e2 And import xamarin-android's `Directory.Build.props` from `xamarin-android-tools.override.props`. With this change in place, I can set the value of `$(LibZipSharpVersion)` to any value and the value from xamarin-android overrides it. This probably slipped through because we dropped the "classic" Xamarin.Android test suite that used .NET framework MSBuild on Windows. All tests now use `dotnet build`. I added a test that builds an Android project in Debug & Release with `MSBuild.exe`, and updated Xamarin.ProjectTools to support doing this.
1 parent a850d81 commit b0bac43

File tree

8 files changed

+48
-23
lines changed

8 files changed

+48
-23
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project>
2+
<Import Project="..\Directory.Build.props" />
3+
</Project>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,5 +2577,27 @@ public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrim
25772577
using var builder = CreateApkBuilder ();
25782578
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
25792579
}
2580+
2581+
/// <summary>
2582+
/// Build with MSBuild.exe on .NET framework, instead of 'dotnet build'
2583+
/// </summary>
2584+
[Test]
2585+
public void BuildWithMSBuild ([Values (true, false)] bool isRelease)
2586+
{
2587+
if (!IsWindows)
2588+
Assert.Ignore ("Test is only valid on Windows platforms");
2589+
2590+
var proj = new XamarinAndroidApplicationProject {
2591+
IsRelease = isRelease,
2592+
};
2593+
using var builder = CreateApkBuilder ();
2594+
2595+
// Use MSBuild.exe, setting %PATH% to our local 'dotnet' directory
2596+
builder.BuildTool = TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
2597+
var environment = new Dictionary<string, string> ();
2598+
environment ["PATH"] = $"{TestEnvironment.DotNetPreviewDirectory};{Environment.GetEnvironmentVariable ("PATH")}";
2599+
2600+
Assert.IsTrue (builder.Build (proj, environmentVariables: environment), "Build should have succeeded.");
2601+
}
25802602
}
25812603
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/MSBuildSdkExtrasProject.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public MSBuildSdkExtrasProject ()
2020

2121
public string StringsXml { get; set; }
2222

23-
/// <summary>
24-
/// /t:Restore or /restore is always required
25-
/// </summary>
26-
public override bool ShouldRestorePackageReferences => true;
27-
2823
public string TargetFrameworks {
2924
get => GetProperty (nameof (TargetFrameworks));
3025
set => SetProperty (nameof (TargetFrameworks), value);

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/Builder.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ public IEnumerable<string> LastBuildOutput {
5353
/// </summary>
5454
public bool AutomaticNuGetRestore { get; set; } = true;
5555

56+
string _buildTool;
57+
5658
public string BuildTool {
57-
get {
58-
if (UseDotNet)
59-
return Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");
59+
get => _buildTool ??= FindBuildTool ();
60+
set => _buildTool = value;
61+
}
6062

61-
string xabuild = IsUnix ? XABuildPaths.XABuildScript : XABuildPaths.XABuildExe;
62-
if (File.Exists (xabuild) && TestEnvironment.UseLocalBuildOutput)
63-
return xabuild;
64-
return IsUnix ? "msbuild" : TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
65-
}
63+
string FindBuildTool ()
64+
{
65+
if (UseDotNet)
66+
return Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");
67+
68+
string xabuild = IsUnix ? XABuildPaths.XABuildScript : XABuildPaths.XABuildExe;
69+
if (File.Exists (xabuild) && TestEnvironment.UseLocalBuildOutput)
70+
return xabuild;
71+
return IsUnix ? "msbuild" : TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
6672
}
6773

6874
public bool CrossCompilerAvailable (string supportedAbis)
@@ -186,7 +192,7 @@ protected virtual void Dispose (bool disposing)
186192
RegexOptions.Multiline | RegexOptions.Compiled
187193
);
188194

189-
protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null, bool restore = true, string binlogName = "msbuild")
195+
protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null, string binlogName = "msbuild")
190196
{
191197
buildLogFullPath = (!string.IsNullOrEmpty (BuildLogFile))
192198
? Path.GetFullPath (Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), BuildLogFile))
@@ -204,20 +210,23 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
204210
var args = new StringBuilder ();
205211
var psi = new ProcessStartInfo (BuildTool);
206212
var responseFile = Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), "project.rsp");
213+
var isMSBuild = string.Equals (Path.GetFileNameWithoutExtension (psi.FileName), "MSBuild", StringComparison.OrdinalIgnoreCase);
207214
if (UseDotNet) {
208-
args.Append ("build ");
215+
if (!isMSBuild) {
216+
args.Append ("build ");
217+
}
209218
if (TestEnvironment.UseLocalBuildOutput) {
210219
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", TestEnvironment.WorkloadManifestOverridePath);
211220
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_PACK_ROOTS", TestEnvironment.WorkloadPackOverridePath);
212221
}
213222
}
214223
args.AppendFormat ("{0} /t:{1} {2}",
215224
QuoteFileName (Path.Combine (XABuildPaths.TestOutputDirectory, projectOrSolution)), target, logger);
216-
if (UseDotNet) {
225+
if (UseDotNet && !isMSBuild) {
217226
if (!AutomaticNuGetRestore) {
218227
args.Append (" --no-restore");
219228
}
220-
} else if (AutomaticNuGetRestore && restore) {
229+
} else if (AutomaticNuGetRestore) {
221230
args.Append (" /restore");
222231
}
223232

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetStandard.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public DotNetStandard ()
2323
Language = XamarinAndroidProjectLanguage.CSharp;
2424
}
2525

26-
// NetStandard projects always need to restore
27-
public override bool ShouldRestorePackageReferences => true;
28-
2926
public string PackageTargetFallback {
3027
get { return GetProperty ("PackageTargetFallback"); }
3128
set { SetProperty ("PackageTargetFallback", value); }

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool Build (XamarinProject project, bool doNotCleanupOnUpdate = false, st
7070
project.NuGetRestore (Path.Combine (XABuildPaths.TestOutputDirectory, ProjectDirectory), PackagesDirectory);
7171
}
7272

73-
bool result = BuildInternal (Path.Combine (ProjectDirectory, project.ProjectFilePath), Target, parameters, environmentVariables, restore: project.ShouldRestorePackageReferences, binlogName: Path.GetFileNameWithoutExtension (BuildLogFile));
73+
bool result = BuildInternal (Path.Combine (ProjectDirectory, project.ProjectFilePath), Target, parameters, environmentVariables, binlogName: Path.GetFileNameWithoutExtension (BuildLogFile));
7474
built_before = true;
7575

7676
if (CleanupAfterSuccessfulBuild)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/SolutionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void Save ()
6767

6868
public bool BuildProject(XamarinProject project, string target = "Build")
6969
{
70-
BuildSucceeded = BuildInternal(Path.Combine (SolutionPath, project.ProjectName, project.ProjectFilePath), target, restore: project.ShouldRestorePackageReferences);
70+
BuildSucceeded = BuildInternal(Path.Combine (SolutionPath, project.ProjectName, project.ProjectFilePath), target);
7171
return BuildSucceeded;
7272
}
7373

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public abstract class XamarinProject
3333
public string GlobalPackagesFolder { get; set; } = FileSystemUtils.FindNugetGlobalPackageFolder ();
3434
public IList<string> ExtraNuGetConfigSources { get; set; } = new List<string> ();
3535

36-
public virtual bool ShouldRestorePackageReferences => PackageReferences?.Count > 0;
3736
/// <summary>
3837
/// If true, the ProjectDirectory will be deleted and populated on the first build
3938
/// </summary>

0 commit comments

Comments
 (0)