Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] create xamarin-android-tools.override.props #8145

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions external/xamarin-android-tools.override.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="..\Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2577,5 +2577,27 @@ public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrim
using var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
}

/// <summary>
/// Build with MSBuild.exe on .NET framework, instead of 'dotnet build'
/// </summary>
[Test]
public void BuildWithMSBuild ([Values (true, false)] bool isRelease)
{
if (!IsWindows)
Assert.Ignore ("Test is only valid on Windows platforms");

var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
};
using var builder = CreateApkBuilder ();

// Use MSBuild.exe, setting %PATH% to our local 'dotnet' directory
builder.BuildTool = TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
var environment = new Dictionary<string, string> ();
environment ["PATH"] = $"{TestEnvironment.DotNetPreviewDirectory};{Environment.GetEnvironmentVariable ("PATH")}";

Assert.IsTrue (builder.Build (proj, environmentVariables: environment), "Build should have succeeded.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public MSBuildSdkExtrasProject ()

public string StringsXml { get; set; }

/// <summary>
/// /t:Restore or /restore is always required
/// </summary>
public override bool ShouldRestorePackageReferences => true;

public string TargetFrameworks {
get => GetProperty (nameof (TargetFrameworks));
set => SetProperty (nameof (TargetFrameworks), value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@ public IEnumerable<string> LastBuildOutput {
/// </summary>
public bool AutomaticNuGetRestore { get; set; } = true;

string _buildTool;

public string BuildTool {
get {
if (UseDotNet)
return Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");
get => _buildTool ??= FindBuildTool ();
set => _buildTool = value;
}

string xabuild = IsUnix ? XABuildPaths.XABuildScript : XABuildPaths.XABuildExe;
if (File.Exists (xabuild) && TestEnvironment.UseLocalBuildOutput)
return xabuild;
return IsUnix ? "msbuild" : TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
}
string FindBuildTool ()
{
if (UseDotNet)
return Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");

string xabuild = IsUnix ? XABuildPaths.XABuildScript : XABuildPaths.XABuildExe;
if (File.Exists (xabuild) && TestEnvironment.UseLocalBuildOutput)
return xabuild;
return IsUnix ? "msbuild" : TestEnvironment.GetVisualStudioInstance ().MSBuildPath;
}

public bool CrossCompilerAvailable (string supportedAbis)
Expand Down Expand Up @@ -186,7 +192,7 @@ protected virtual void Dispose (bool disposing)
RegexOptions.Multiline | RegexOptions.Compiled
);

protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null, bool restore = true, string binlogName = "msbuild")
protected bool BuildInternal (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null, string binlogName = "msbuild")
{
buildLogFullPath = (!string.IsNullOrEmpty (BuildLogFile))
? Path.GetFullPath (Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), BuildLogFile))
Expand All @@ -204,20 +210,23 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
var args = new StringBuilder ();
var psi = new ProcessStartInfo (BuildTool);
var responseFile = Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), "project.rsp");
var isMSBuild = string.Equals (Path.GetFileNameWithoutExtension (psi.FileName), "MSBuild", StringComparison.OrdinalIgnoreCase);
if (UseDotNet) {
args.Append ("build ");
if (!isMSBuild) {
args.Append ("build ");
}
if (TestEnvironment.UseLocalBuildOutput) {
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", TestEnvironment.WorkloadManifestOverridePath);
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_PACK_ROOTS", TestEnvironment.WorkloadPackOverridePath);
}
}
args.AppendFormat ("{0} /t:{1} {2}",
QuoteFileName (Path.Combine (XABuildPaths.TestOutputDirectory, projectOrSolution)), target, logger);
if (UseDotNet) {
if (UseDotNet && !isMSBuild) {
if (!AutomaticNuGetRestore) {
args.Append (" --no-restore");
}
} else if (AutomaticNuGetRestore && restore) {
} else if (AutomaticNuGetRestore) {
args.Append (" /restore");
}

Expand Down Expand Up @@ -256,6 +265,7 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
}

psi.SetEnvironmentVariable ("MSBUILD", "msbuild");
psi.SetEnvironmentVariable ("MSBUILDLOGALLENVIRONMENTVARIABLES", "1"); // So .binlog files contain all env vars
sw.WriteLine ($"/bl:\"{Path.GetFullPath (Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), $"{binlogName}.binlog"))}\"");

if (environmentVariables != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public DotNetStandard ()
Language = XamarinAndroidProjectLanguage.CSharp;
}

// NetStandard projects always need to restore
public override bool ShouldRestorePackageReferences => true;

public string PackageTargetFallback {
get { return GetProperty ("PackageTargetFallback"); }
set { SetProperty ("PackageTargetFallback", value); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public bool Build (XamarinProject project, bool doNotCleanupOnUpdate = false, st
project.NuGetRestore (Path.Combine (XABuildPaths.TestOutputDirectory, ProjectDirectory), PackagesDirectory);
}

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

if (CleanupAfterSuccessfulBuild)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Save ()

public bool BuildProject(XamarinProject project, string target = "Build")
{
BuildSucceeded = BuildInternal(Path.Combine (SolutionPath, project.ProjectName, project.ProjectFilePath), target, restore: project.ShouldRestorePackageReferences);
BuildSucceeded = BuildInternal(Path.Combine (SolutionPath, project.ProjectName, project.ProjectFilePath), target);
return BuildSucceeded;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public abstract class XamarinProject
public string GlobalPackagesFolder { get; set; } = FileSystemUtils.FindNugetGlobalPackageFolder ();
public IList<string> ExtraNuGetConfigSources { get; set; } = new List<string> ();

public virtual bool ShouldRestorePackageReferences => PackageReferences?.Count > 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET 6+ projects always need to restore, so I removed this in main going forward.

/// <summary>
/// If true, the ProjectDirectory will be deleted and populated on the first build
/// </summary>
Expand Down