Cleanup cake file, add targets, fix for iOS Pair (#7241)
* Cleanup cake file, add targets, fix for iOS Pair * - fix sln argument * - add dogfood ps1 * - pack maui before opening external sln * - add "pack" argument * - exit earlier * - script cleanup * - move dogfood into cake and condtionally run * - fix pack checks * - open VS even if build tasks fail to build * - change to warning * - change CI check to error * - set dotnet_root * - fix vsmac * - changes to omnisharp * - switch to flags * - fix clean
This commit is contained in:
Родитель
689dcaa0f8
Коммит
cb2014b6ff
1252
build.cake
1252
build.cake
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -2,6 +2,11 @@
|
|||
|
||||
var ext = IsRunningOnWindows() ? ".exe" : "";
|
||||
var dotnetPath = $"./bin/dotnet/dotnet{ext}";
|
||||
string configuration = GetBuildVariable("configuration", GetBuildVariable("BUILD_CONFIGURATION", "DEBUG"));
|
||||
var localDotnet = GetBuildVariable("workloads", "local") == "local";
|
||||
var vsVersion = GetBuildVariable("VS", "");
|
||||
string MSBuildExe = Argument("msbuild", EnvironmentVariable("MSBUILD_EXE", ""));
|
||||
Exception pendingException = null;
|
||||
|
||||
// Tasks for CI
|
||||
|
||||
|
@ -15,7 +20,7 @@ Task("dotnet")
|
|||
DotNetCoreBuild("./src/DotNet/DotNet.csproj", new DotNetCoreBuildSettings
|
||||
{
|
||||
MSBuildSettings = new DotNetCoreMSBuildSettings()
|
||||
.EnableBinaryLogger($"{logDirectory}/dotnet-{configuration}.binlog")
|
||||
.EnableBinaryLogger($"{GetLogDirectory()}/dotnet-{configuration}.binlog")
|
||||
.SetConfiguration(configuration),
|
||||
});
|
||||
});
|
||||
|
@ -29,7 +34,7 @@ Task("dotnet-local-workloads")
|
|||
DotNetCoreBuild("./src/DotNet/DotNet.csproj", new DotNetCoreBuildSettings
|
||||
{
|
||||
MSBuildSettings = new DotNetCoreMSBuildSettings()
|
||||
.EnableBinaryLogger($"{logDirectory}/dotnet-{configuration}.binlog")
|
||||
.EnableBinaryLogger($"{GetLogDirectory()}/dotnet-{configuration}.binlog")
|
||||
.SetConfiguration(configuration)
|
||||
.WithProperty("InstallWorkloadPacks", "false"),
|
||||
});
|
||||
|
@ -37,7 +42,7 @@ Task("dotnet-local-workloads")
|
|||
DotNetCoreBuild("./src/DotNet/DotNet.csproj", new DotNetCoreBuildSettings
|
||||
{
|
||||
MSBuildSettings = new DotNetCoreMSBuildSettings()
|
||||
.EnableBinaryLogger($"{logDirectory}/dotnet-install-{configuration}.binlog")
|
||||
.EnableBinaryLogger($"{GetLogDirectory()}/dotnet-install-{configuration}.binlog")
|
||||
.SetConfiguration(configuration)
|
||||
.WithTarget("Install"),
|
||||
ToolPath = dotnetPath,
|
||||
|
@ -45,10 +50,21 @@ Task("dotnet-local-workloads")
|
|||
});
|
||||
|
||||
Task("dotnet-buildtasks")
|
||||
.WithCriteria(Argument<string>("sln", null) == null)
|
||||
.IsDependentOn("dotnet")
|
||||
.Does(() =>
|
||||
{
|
||||
RunMSBuildWithDotNet("./Microsoft.Maui.BuildTasks.slnf");
|
||||
})
|
||||
.OnError(exception =>
|
||||
{
|
||||
if (IsTarget("VS"))
|
||||
{
|
||||
pendingException = exception;
|
||||
return;
|
||||
}
|
||||
|
||||
throw exception;
|
||||
});
|
||||
|
||||
Task("dotnet-build")
|
||||
|
@ -80,7 +96,7 @@ Task("dotnet-templates")
|
|||
|
||||
var dn = localDotnet ? dotnetPath : "dotnet";
|
||||
|
||||
var templatesTest = tempDirectory.Combine("templatesTest");
|
||||
var templatesTest = GetTempDirectory().Combine("templatesTest");
|
||||
|
||||
EnsureDirectoryExists(templatesTest);
|
||||
CleanDirectories(templatesTest.FullPath);
|
||||
|
@ -210,6 +226,7 @@ Task("dotnet-test")
|
|||
});
|
||||
|
||||
Task("dotnet-pack-maui")
|
||||
.WithCriteria(RunPackTarget())
|
||||
.Does(() =>
|
||||
{
|
||||
DotNetCoreTool("pwsh", new DotNetCoreToolSettings
|
||||
|
@ -220,6 +237,7 @@ Task("dotnet-pack-maui")
|
|||
});
|
||||
|
||||
Task("dotnet-pack-additional")
|
||||
.WithCriteria(RunPackTarget())
|
||||
.Does(() =>
|
||||
{
|
||||
// Download some additional symbols that need to be archived along with the maui symbols:
|
||||
|
@ -241,6 +259,7 @@ Task("dotnet-pack-additional")
|
|||
});
|
||||
|
||||
Task("dotnet-pack-library-packs")
|
||||
.WithCriteria(RunPackTarget())
|
||||
.Does(() =>
|
||||
{
|
||||
var tempDir = $"./artifacts/library-packs-temp";
|
||||
|
@ -270,6 +289,7 @@ Task("dotnet-pack-library-packs")
|
|||
});
|
||||
|
||||
Task("dotnet-pack")
|
||||
.WithCriteria(RunPackTarget())
|
||||
.IsDependentOn("dotnet-pack-maui")
|
||||
.IsDependentOn("dotnet-pack-additional")
|
||||
.IsDependentOn("dotnet-pack-library-packs");
|
||||
|
@ -291,11 +311,11 @@ Task("dotnet-diff")
|
|||
else
|
||||
{
|
||||
// clean all working folders
|
||||
var diffCacheDir = tempDirectory.Combine("diffCache");
|
||||
var diffCacheDir = GetTempDirectory().Combine("diffCache");
|
||||
EnsureDirectoryExists(diffCacheDir);
|
||||
CleanDirectories(diffCacheDir.FullPath);
|
||||
EnsureDirectoryExists(diffDirectory);
|
||||
CleanDirectories(diffDirectory.FullPath);
|
||||
EnsureDirectoryExists(GetDiffDirectory());
|
||||
CleanDirectories(GetDiffDirectory().FullPath);
|
||||
|
||||
// run the diff
|
||||
foreach (var nupkg in nupkgs)
|
||||
|
@ -311,7 +331,7 @@ Task("dotnet-diff")
|
|||
.Append("--prerelease")
|
||||
.Append("--group-ids")
|
||||
.Append("--ignore-unchanged")
|
||||
.AppendSwitchQuoted("--output", diffDirectory.FullPath)
|
||||
.AppendSwitchQuoted("--output", GetDiffDirectory().FullPath)
|
||||
.AppendSwitchQuoted("--cache", diffCacheDir.FullPath)
|
||||
});
|
||||
}
|
||||
|
@ -326,7 +346,7 @@ Task("dotnet-diff")
|
|||
Information("Unable to clean up diff cache directory.");
|
||||
}
|
||||
|
||||
var diffs = GetFiles($"{diffDirectory}/**/*.md");
|
||||
var diffs = GetFiles($"{GetDiffDirectory()}/**/*.md");
|
||||
if (!diffs.Any())
|
||||
{
|
||||
Warning($"##vso[task.logissue type=warning]No NuGet diffs were found.");
|
||||
|
@ -366,48 +386,58 @@ Task("dotnet-diff")
|
|||
});
|
||||
|
||||
// Tasks for Local Development
|
||||
|
||||
Task("VS-DOGFOOD")
|
||||
.Description("Provisions .NET 6 and launches an instance of Visual Studio using it.")
|
||||
Task("VS")
|
||||
.Description("Provisions .NET 6, and launches an instance of Visual Studio using it.")
|
||||
.IsDependentOn("Clean")
|
||||
.IsDependentOn("dotnet")
|
||||
.IsDependentOn("dotnet-buildtasks")
|
||||
.IsDependentOn("dotnet-pack") // Run conditionally
|
||||
.Does(() =>
|
||||
{
|
||||
StartVisualStudioForDotNet6(null);
|
||||
});
|
||||
if (pendingException != null)
|
||||
{
|
||||
Error($"{pendingException}");
|
||||
Error("!!!!BUILD TASKS FAILED: !!!!!");
|
||||
}
|
||||
|
||||
StartVisualStudioForDotNet6();
|
||||
});
|
||||
|
||||
// Keeping this for users that are already using this.
|
||||
Task("VS-NET6")
|
||||
.Description("Provisions .NET 6 and launches an instance of Visual Studio using it.")
|
||||
.IsDependentOn("Clean")
|
||||
.IsDependentOn("dotnet")
|
||||
.IsDependentOn("dotnet-buildtasks")
|
||||
.IsDependentOn("VS")
|
||||
.Does(() =>
|
||||
{
|
||||
StartVisualStudioForDotNet6();
|
||||
Warning("!!!!Please switch to using the `VS` target.!!!!");
|
||||
});
|
||||
|
||||
Task("VS-WINUI")
|
||||
.Description("Provisions .NET 6 and launches an instance of Visual Studio with WinUI projects.")
|
||||
.IsDependentOn("VS-NET6");
|
||||
// .IsDependentOn("dotnet") WINUI currently can't launch application with local dotnet
|
||||
// .IsDependentOn("dotnet-buildtasks")
|
||||
bool RunPackTarget()
|
||||
{
|
||||
// Is the user running the pack target explicitly?
|
||||
if (TargetStartsWith("dotnet-pack"))
|
||||
return true;
|
||||
|
||||
Task("VS-ANDROID")
|
||||
.Description("Provisions .NET 6 and launches an instance of Visual Studio with Android projects.")
|
||||
.IsDependentOn("Clean")
|
||||
.IsDependentOn("dotnet")
|
||||
.IsDependentOn("dotnet-buildtasks")
|
||||
.Does(() =>
|
||||
// If the default target is running then let the pack target run
|
||||
if (IsTarget("Default"))
|
||||
return true;
|
||||
|
||||
// Does the user want to run a pack as part of a different target?
|
||||
if (HasArgument("pack"))
|
||||
return true;
|
||||
|
||||
// If the request is to open a different sln then let's see if pack has ever run
|
||||
// if it hasn't then lets pack maui so the sln will open
|
||||
if (Argument<string>("sln", null) != null)
|
||||
{
|
||||
DotNetCoreRestore("./Microsoft.Maui.sln", new DotNetCoreRestoreSettings
|
||||
{
|
||||
ToolPath = dotnetPath
|
||||
});
|
||||
var mauiPacks = MakeAbsolute(Directory("./bin/dotnet/packs/Microsoft.Maui.Sdk")).ToString();
|
||||
if (!DirectoryExists(mauiPacks))
|
||||
return true;
|
||||
}
|
||||
|
||||
// VS has trouble building all the references correctly so this makes sure everything is built
|
||||
// and we're ready to go right when VS launches
|
||||
RunMSBuildWithDotNet("./src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj");
|
||||
StartVisualStudioForDotNet6("./Microsoft.Maui.Droid.sln");
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
string FindMSBuild()
|
||||
{
|
||||
|
@ -431,6 +461,30 @@ string FindMSBuild()
|
|||
return "msbuild";
|
||||
}
|
||||
|
||||
|
||||
Dictionary<string, string> GetDotNetEnvironmentVariables()
|
||||
{
|
||||
Dictionary<string, string> envVariables = new Dictionary<string, string>();
|
||||
var dotnet = MakeAbsolute(Directory("./bin/dotnet/")).ToString();
|
||||
|
||||
envVariables.Add("DOTNET_INSTALL_DIR", dotnet);
|
||||
envVariables.Add("DOTNET_ROOT", dotnet);
|
||||
envVariables.Add("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", dotnet);
|
||||
envVariables.Add("DOTNET_MULTILEVEL_LOOKUP", "0");
|
||||
envVariables.Add("MSBuildEnableWorkloadResolver", "true");
|
||||
|
||||
var existingPath = EnvironmentVariable("PATH");
|
||||
Information(dotnet + ":" + existingPath);
|
||||
envVariables.Add("PATH", dotnet + ":" + existingPath);
|
||||
|
||||
// Get "full" .binlog in Project System Tools
|
||||
if (HasArgument("debug"))
|
||||
envVariables.Add("MSBuildDebugEngine", "1");
|
||||
|
||||
return envVariables;
|
||||
|
||||
}
|
||||
|
||||
void SetDotNetEnvironmentVariables()
|
||||
{
|
||||
var dotnet = MakeAbsolute(Directory("./bin/dotnet/")).ToString();
|
||||
|
@ -441,11 +495,22 @@ void SetDotNetEnvironmentVariables()
|
|||
SetEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0");
|
||||
SetEnvironmentVariable("MSBuildEnableWorkloadResolver", "true");
|
||||
SetEnvironmentVariable("PATH", dotnet, prepend: true);
|
||||
|
||||
// Get "full" .binlog in Project System Tools
|
||||
if (HasArgument("debug"))
|
||||
SetEnvironmentVariable("MSBuildDebugEngine", "1");
|
||||
}
|
||||
|
||||
void StartVisualStudioForDotNet6(string sln = null)
|
||||
void StartVisualStudioForDotNet6()
|
||||
{
|
||||
if (sln == null)
|
||||
string sln = Argument<string>("sln", null);
|
||||
|
||||
bool includePrerelease = true;
|
||||
|
||||
if (!String.IsNullOrEmpty(vsVersion))
|
||||
includePrerelease = (vsVersion == "preview");
|
||||
|
||||
if (String.IsNullOrWhiteSpace(sln))
|
||||
{
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
|
@ -453,35 +518,34 @@ void StartVisualStudioForDotNet6(string sln = null)
|
|||
}
|
||||
else
|
||||
{
|
||||
sln = "./Microsoft.Maui-mac.slnf";
|
||||
sln = "_omnisharp.sln";
|
||||
}
|
||||
}
|
||||
if (isCIBuild)
|
||||
|
||||
if (IsCIBuild())
|
||||
{
|
||||
Information("This target should not run on CI.");
|
||||
Error("This target should not run on CI.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(localDotnet)
|
||||
{
|
||||
SetDotNetEnvironmentVariables();
|
||||
SetEnvironmentVariable("_ExcludeMauiProjectCapability", "true");
|
||||
}
|
||||
|
||||
if (IsRunningOnWindows())
|
||||
{
|
||||
bool includePrerelease = true;
|
||||
|
||||
if (!String.IsNullOrEmpty(vsVersion))
|
||||
includePrerelease = (vsVersion == "preview");
|
||||
|
||||
var vsLatest = VSWhereLatest(new VSWhereLatestSettings { IncludePrerelease = includePrerelease, });
|
||||
if (vsLatest == null)
|
||||
throw new Exception("Unable to find Visual Studio!");
|
||||
|
||||
|
||||
StartProcess(vsLatest.CombineWithFilePath("./Common7/IDE/devenv.exe"), sln);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartProcess("open", new ProcessSettings{ Arguments = sln });
|
||||
|
||||
StartProcess("open", new ProcessSettings{ Arguments = sln, EnvironmentVariables = GetDotNetEnvironmentVariables() });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -501,8 +565,8 @@ void RunMSBuildWithDotNet(
|
|||
var name = System.IO.Path.GetFileNameWithoutExtension(sln);
|
||||
var type = useDotNetBuild ? "dotnet" : "msbuild";
|
||||
var binlog = string.IsNullOrEmpty(targetFramework) ?
|
||||
$"\"{logDirectory}/{name}-{configuration}-{target}-{type}.binlog\"" :
|
||||
$"\"{logDirectory}/{name}-{configuration}-{target}-{targetFramework}-{type}.binlog\"";
|
||||
$"\"{GetLogDirectory()}/{name}-{configuration}-{target}-{type}.binlog\"" :
|
||||
$"\"{GetLogDirectory()}/{name}-{configuration}-{target}-{targetFramework}-{type}.binlog\"";
|
||||
|
||||
if(localDotnet)
|
||||
SetDotNetEnvironmentVariables();
|
||||
|
@ -533,6 +597,7 @@ void RunMSBuildWithDotNet(
|
|||
{
|
||||
MSBuildSettings = msbuildSettings,
|
||||
};
|
||||
|
||||
dotnetBuildSettings.ArgumentCustomization = args =>
|
||||
{
|
||||
if (!restore)
|
||||
|
@ -588,7 +653,7 @@ void RunMSBuildWithDotNet(
|
|||
void RunTestWithLocalDotNet(string csproj)
|
||||
{
|
||||
var name = System.IO.Path.GetFileNameWithoutExtension(csproj);
|
||||
var binlog = $"{logDirectory}/{name}-{configuration}.binlog";
|
||||
var binlog = $"{GetLogDirectory()}/{name}-{configuration}.binlog";
|
||||
var results = $"{name}-{configuration}.trx";
|
||||
|
||||
if(localDotnet)
|
||||
|
@ -601,7 +666,7 @@ void RunTestWithLocalDotNet(string csproj)
|
|||
ToolPath = dotnetPath,
|
||||
NoBuild = true,
|
||||
Logger = $"trx;LogFileName={results}",
|
||||
ResultsDirectory = testResultsDirectory,
|
||||
ResultsDirectory = GetTestResultsDirectory(),
|
||||
ArgumentCustomization = args => args.Append($"-bl:{binlog}")
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
bool isCleanSet = HasArgument("clean") || IsTarget("clean");
|
||||
|
||||
Task("Clean")
|
||||
.WithCriteria(isCleanSet)
|
||||
.Description("Deletes all the obj/bin directories")
|
||||
.Does(() =>
|
||||
{
|
||||
|
@ -21,7 +24,34 @@ Task("Clean")
|
|||
}
|
||||
});
|
||||
|
||||
DirectoryPath _artifactStagingDirectory;
|
||||
DirectoryPath GetArtifactStagingDirectory() =>
|
||||
_artifactStagingDirectory ??= MakeAbsolute(Directory(EnvironmentVariable("BUILD_ARTIFACTSTAGINGDIRECTORY", "artifacts")));
|
||||
|
||||
DirectoryPath _logDirectory;
|
||||
DirectoryPath GetLogDirectory() =>
|
||||
_logDirectory ??= MakeAbsolute(Directory(EnvironmentVariable("LogDirectory", $"{GetArtifactStagingDirectory()}/logs")));
|
||||
|
||||
DirectoryPath _testResultsDirectory;
|
||||
DirectoryPath GetTestResultsDirectory() =>
|
||||
_testResultsDirectory ??= MakeAbsolute(Directory(EnvironmentVariable("TestResultsDirectory", $"{GetArtifactStagingDirectory()}/test-results")));
|
||||
|
||||
DirectoryPath _diffDirectory;
|
||||
DirectoryPath GetDiffDirectory() =>
|
||||
_diffDirectory ??= MakeAbsolute(Directory(EnvironmentVariable("ApiDiffDirectory", $"{GetArtifactStagingDirectory()}/api-diff")));
|
||||
|
||||
DirectoryPath _tempDirectory;
|
||||
DirectoryPath GetTempDirectory() =>
|
||||
_tempDirectory ??= MakeAbsolute(Directory(EnvironmentVariable("AGENT_TEMPDIRECTORY", EnvironmentVariable("TEMP", EnvironmentVariable("TMPDIR", "../maui-temp")) + "/" + Guid.NewGuid())));
|
||||
|
||||
string GetAgentName() =>
|
||||
EnvironmentVariable("AGENT_NAME", "");
|
||||
|
||||
bool IsCIBuild() =>
|
||||
!String.IsNullOrWhiteSpace(GetAgentName());
|
||||
|
||||
bool IsHostedAgent() =>
|
||||
GetAgentName().StartsWith("Azure Pipelines") || GetAgentName().StartsWith("Hosted Agent");
|
||||
|
||||
T GetBuildVariable<T>(string key, T defaultValue)
|
||||
{
|
||||
|
@ -85,3 +115,9 @@ void SetEnvironmentVariable(string name, string value, bool prepend = false)
|
|||
|
||||
Information("Setting environment variable: {0} = '{1}'", name, value);
|
||||
}
|
||||
|
||||
bool IsTarget(string target) =>
|
||||
Argument<string>("target", "Default").Equals(target, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
bool TargetStartsWith(string target) =>
|
||||
Argument<string>("target", "Default").StartsWith(target, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
|
|
@ -101,12 +101,16 @@ if ($IsWindows)
|
|||
else
|
||||
{
|
||||
$oldPATH=$env:PATH
|
||||
$oldDOTNET_ROOT=$env:DOTNET_ROOT
|
||||
try
|
||||
{
|
||||
# Put our local dotnet on $PATH
|
||||
$env:PATH=($dotnet + [IO.Path]::PathSeparator + $env:PATH)
|
||||
$dotnet_tool = Join-Path $dotnet dotnet
|
||||
|
||||
# This tells .NET to use the bootstrapped runtime
|
||||
$env:DOTNET_ROOT=$dotnet
|
||||
|
||||
# Build with ./bin/dotnet/dotnet
|
||||
& $dotnet_tool pack $slnMac `
|
||||
-c:$configuration `
|
||||
|
@ -117,5 +121,6 @@ else
|
|||
finally
|
||||
{
|
||||
$env:PATH=$oldPATH
|
||||
$env:DOTNET_ROOT=$oldDOTNET_ROOT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,14 @@
|
|||
<RemoveDir Directories="$(DotNetDirectory)" />
|
||||
<Exec Command="$(DotNetInstallCommand)" />
|
||||
<Touch Files="$(DotNetDirectory).stamp" AlwaysCreate="true" />
|
||||
|
||||
<!-- This is used by iOS pair to mac because pair to mac can't
|
||||
determine the version of preview versions. -->
|
||||
<WriteLinesToFile
|
||||
File="$(DotNetDirectory)dotnet-sdk-version.txt"
|
||||
Lines="$(MicrosoftDotnetSdkInternalPackageVersion)"
|
||||
Condition="$([MSBuild]::IsOSPlatform('windows'))"
|
||||
Overwrite="true" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче