Skip to content

[tests] introduce test that builds with MSBuild.exe #8746

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ public void BuildBasicApplication ([Values (true, false)] bool isRelease, [Value
}
}

[Test]
public void BuildWithMSBuildExe ([Values (true, false)] bool isRelease)
{
if (!IsWindows)
Assert.Ignore ("Test is only valid on Windows");

var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
};

using var b = CreateApkBuilder ();
b.UseMSBuildExe = true;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
}

[Test]
public void BuildBasicApplicationThenMoveIt ([Values (true, false)] bool isRelease)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Xml.XPath;
using System.Xml.Linq;
using Xamarin.Android.Tools.VSWhere;

namespace Xamarin.ProjectTools
{
Expand Down Expand Up @@ -142,6 +143,22 @@ public Builder ()
BuildLogFile = "build.log";
}

/// <summary>
/// Build with MSBuild.exe from Visual Studio, only works on Windows
/// </summary>
public bool UseMSBuildExe { get; set; }

/// <summary>
/// Value for %MSBuildSdksPath%, points to bin\Release\dotnet\sdk\*\Sdks
/// </summary>
public string MSBuildSdksPath {
get {
var sdk = Path.Combine (TestEnvironment.DotNetPreviewDirectory, "sdk");
var sdk_version = Directory.EnumerateDirectories (sdk).OrderByDescending (x => x).First ();
return Path.Combine (sdk_version, "Sdks");
}
}

public void Dispose ()
{
Dispose (true);
Expand Down Expand Up @@ -173,9 +190,20 @@ protected bool BuildInternal (string projectOrSolution, string target, string []

var start = DateTime.UtcNow;
var args = new StringBuilder ();
var psi = new ProcessStartInfo (Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet"));
var psi = new ProcessStartInfo ();
var responseFile = Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), "project.rsp");
args.Append ("build ");
if (UseMSBuildExe) {
psi.FileName = MSBuildLocator.QueryLatest ().MSBuildPath;
args.Append ("/restore ");
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_PACK_ROOTS", Path.Combine (TestEnvironment.DotNetPreviewDirectory, "packs"));
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", Path.Combine (TestEnvironment.DotNetPreviewDirectory, "sdk-manifests"));
psi.SetEnvironmentVariable ("MSBUILDLOGALLENVIRONMENTVARIABLES", "1");
psi.SetEnvironmentVariable ("MSBuildSDKsPath", MSBuildSdksPath);
psi.SetEnvironmentVariable ("PATH", TestEnvironment.DotNetPreviewDirectory + Path.PathSeparator + Environment.GetEnvironmentVariable ("PATH"));
} else {
psi.FileName = Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");
args.Append ("build ");
}

if (TestEnvironment.UseLocalBuildOutput) {
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", TestEnvironment.WorkloadManifestOverridePath);
Expand Down