Skip to content

Commit

Permalink
Use dotnet-cake for performing the build
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Jun 1, 2023
1 parent 42e49b4 commit 8467f28
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.1.0",
"version": "3.0.0",
"commands": [
"dotnet-cake"
]
}
}
}
}
44 changes: 21 additions & 23 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Task("GitVersion")
/// </summary>
Task("Setup")
.IsDependentOn("ValidateMono")
.IsDependentOn("InstallDotNetCoreSdk");
.IsDependentOn("InstallDotNetSdk");

void InstallDotNetSdk(BuildEnvironment env, BuildPlan plan, string version, string installFolder, bool sharedRuntime = false, bool noPath = false)
{
Expand All @@ -73,10 +73,7 @@ void InstallDotNetSdk(BuildEnvironment env, BuildPlan plan, string version, stri
var scriptFilePath = CombinePaths(installFolder, scriptFileName);
var url = $"{plan.DotNetInstallScriptURL}/{scriptFileName}";

using (var client = new WebClient())
{
client.DownloadFile(url, scriptFilePath);
}
DownloadFile(url, File(scriptFilePath));

if (!Platform.Current.IsWindows)
{
Expand Down Expand Up @@ -110,7 +107,7 @@ void InstallDotNetSdk(BuildEnvironment env, BuildPlan plan, string version, stri
Run(env.ShellCommand, $"{env.ShellArgument} {scriptFilePath} {string.Join(" ", argList)}").ExceptionOnError($"Failed to Install .NET Core SDK {version}");
}

Task("InstallDotNetCoreSdk")
Task("InstallDotNetSdk")
.Does(() =>
{
if (!useGlobalDotNetSdk)
Expand Down Expand Up @@ -157,21 +154,21 @@ Task("PrepareTestAssets:CommonTestAssets")
var folder = CombinePaths(env.Folders.TestAssets, "test-projects", project);
try {
DotNetCoreBuild(folder, new DotNetCoreBuildSettings()
DotNetBuild(folder, new DotNetBuildSettings()
{
ToolPath = env.DotNetCommand,
WorkingDirectory = folder,
Verbosity = DotNetCoreVerbosity.Minimal
Verbosity = DotNetVerbosity.Minimal
});
} catch {
// ExternalAlias has issues once in a while, try building again to get it working.
if (project == "ExternAlias") {
DotNetCoreBuild(folder, new DotNetCoreBuildSettings()
DotNetBuild(folder, new DotNetBuildSettings()
{
ToolPath = env.DotNetCommand,
WorkingDirectory = folder,
Verbosity = DotNetCoreVerbosity.Minimal
Verbosity = DotNetVerbosity.Minimal
});
}
}
Expand All @@ -185,11 +182,11 @@ Task("PrepareTestAssets:RestoreOnlyTestAssets")
var folder = CombinePaths(env.Folders.TestAssets, "test-projects", project);
DotNetCoreRestore(new DotNetCoreRestoreSettings()
DotNetRestore(new DotNetRestoreSettings()
{
ToolPath = env.DotNetCommand,
WorkingDirectory = folder,
Verbosity = DotNetCoreVerbosity.Minimal
Verbosity = DotNetVerbosity.Minimal
});
});

Expand All @@ -202,11 +199,11 @@ Task("PrepareTestAssets:WindowsOnlyTestAssets")
var folder = CombinePaths(env.Folders.TestAssets, "test-projects", project);
DotNetCoreBuild(folder, new DotNetCoreBuildSettings()
DotNetBuild(folder, new DotNetBuildSettings()
{
ToolPath = env.DotNetCommand,
WorkingDirectory = folder,
Verbosity = DotNetCoreVerbosity.Minimal
Verbosity = DotNetVerbosity.Minimal
});
});

Expand Down Expand Up @@ -238,14 +235,15 @@ void BuildWithDotNetCli(BuildEnvironment env, string configuration)
? MSBuildBinaryLogImports.Embed
: MSBuildBinaryLogImports.None;

var settings = new DotNetCoreMSBuildSettings
var settings = new DotNetMSBuildSettings
{
WorkingDirectory = env.WorkingDirectory,

ArgumentCustomization = args =>
args.Append("/restore")
.Append($"/bl:{logFileNameBase}.binlog;ProjectImports={projectImports}")
.Append($"/v:{Verbosity.Minimal.GetMSBuildVerbosityName()}")
.Append("/tl")
};

settings.AddFileLogger(
Expand All @@ -268,7 +266,7 @@ void BuildWithDotNetCli(BuildEnvironment env, string configuration)
.WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1") // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward.
.WithProperty("RollForward", "LatestMajor");

DotNetCoreMSBuild("OmniSharp.sln", settings);
DotNetMSBuild("OmniSharp.sln", settings);
}

Task("Build")
Expand Down Expand Up @@ -570,15 +568,15 @@ string PublishBuild(string project, BuildEnvironment env, BuildPlan plan, string

try
{
var publishSettings = new DotNetCorePublishSettings()
var publishSettings = new DotNetPublishSettings()
{
Framework = framework,
Runtime = rid, // TODO: With everything today do we need to publish this with a rid? This appears to be legacy bit when we used to push for all supported dotnet core rids.
PublishReadyToRun = true, // Improve startup performance by applying some AOT compilation
SelfContained = false, // Since we are specifying a runtime identifier this defaults to true. We don't need to ship a runtime for net6 because we require the .NET SDK to be installed.
Configuration = configuration,
OutputDirectory = outputFolder,
MSBuildSettings = new DotNetCoreMSBuildSettings()
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("PackageVersion", env.VersionInfo.NuGetVersion)
.WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer)
.WithProperty("FileVersion", env.VersionInfo.AssemblySemVer)
Expand All @@ -587,9 +585,9 @@ string PublishBuild(string project, BuildEnvironment env, BuildPlan plan, string
.WithProperty("RollForward", "LatestMajor"),
ToolPath = env.DotNetCommand,
WorkingDirectory = env.WorkingDirectory,
Verbosity = DotNetCoreVerbosity.Minimal,
Verbosity = DotNetVerbosity.Minimal,
};
DotNetCorePublish(projectFileName, publishSettings);
DotNetPublish(projectFileName, publishSettings);
}
catch
{
Expand Down Expand Up @@ -645,12 +643,12 @@ Task("PublishWindowsBuilds")
});

Task("PublishNuGet")
.IsDependentOn("InstallDotNetCoreSdk")
.IsDependentOn("InstallDotNetSdk")
.Does(() => {
DotNetCorePack(".", new DotNetCorePackSettings() {
DotNetPack(".", new DotNetPackSettings() {
Configuration = "Release",
OutputDirectory = "./artifacts/nuget/",
MSBuildSettings = new DotNetCoreMSBuildSettings()
MSBuildSettings = new DotNetMSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("PackageVersion", env.VersionInfo.NuGetVersion)
.WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer)
Expand Down
5 changes: 4 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ if (Test-Path $MODULES_PACKAGES_CONFIG) {
Pop-Location
}

Invoke-Expression "&dotnet tool restore"

# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
Expand All @@ -235,5 +237,6 @@ $cakeArguments += $ScriptArgs

# Start Cake
Write-Host "Running build script..."
&$CAKE_EXE $cakeArguments
# &$CAKE_EXE $cakeArguments
dotnet cake $cakeArguments
exit $LASTEXITCODE
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100-preview.4.23260.5",
"version": "8.0.100-preview.3.23178.7",
"rollForward": "patch"
}
}
8 changes: 6 additions & 2 deletions scripts/cake-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"

popd >/dev/null

dotnet tool restore

# Make sure that Cake has been installed.
if [ ! -f "$CAKE_EXE" ]; then
echo "Could not find Cake.exe at '$CAKE_EXE'."
Expand All @@ -95,7 +97,9 @@ fi

# Start Cake
if $SHOW_VERSION; then
exec mono "$CAKE_EXE" --version
# exec mono "$CAKE_EXE" --version
dotnet cake --version
else
exec mono "$CAKE_EXE" $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
# exec mono "$CAKE_EXE" $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
dotnet cake $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
fi
17 changes: 0 additions & 17 deletions scripts/common.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;

public static class Log
{
Expand Down Expand Up @@ -121,22 +120,6 @@ string CombinePaths(params string[] paths)
return PathHelper.Combine(paths);
}

void DownloadFileAndUnzip(string url, string folder)
{
DirectoryHelper.ForceCreate(folder);
var zipFileName = CombinePaths(folder, "temp.zip");

Information("Downloading {0}", url);

using (var client = new WebClient())
{
client.DownloadFile(url, zipFileName);
}

Unzip(zipFileName, folder);
FileHelper.Delete(zipFileName);
}

public class Folders
{
public string DotNetSdk { get; }
Expand Down

0 comments on commit 8467f28

Please sign in to comment.