Skip to content
Merged
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
31 changes: 16 additions & 15 deletions build/Build.Sdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Nuke.Common.Tools.DotNet;
using Serilog;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using Project = Microsoft.Build.Evaluation.Project;
using ProjectProperties = System.Collections.Generic.IReadOnlyDictionary<string, string>;

public partial class Build
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public partial class Build

void PublishCompiler(string? runtimeId)
{
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject(configuration: Configuration);
var compilerProject = Solution.Cesium_Compiler.GetEvaluatedProperties(Configuration);
var runtimeIdDisplayName = runtimeId ?? "<no runtime>";

// The framework-dependent bundle takes a few seconds to publish, so it is always published to never get stale.
Expand All @@ -106,7 +106,7 @@ void PublishCompiler(string? runtimeId)
Log.Information($"Publishing for {runtimeIdDisplayName}, AOT {(PublishAot ? "enabled" : "disabled")}...");
DotNetPublish(o => o
.SetConfiguration(Configuration)
.SetProject(compilerProject.ProjectFileLocation.File)
.SetProject(Solution.Cesium_Compiler.Path)
.SetRuntime(runtimeId)
.SetSelfContained(runtimeId != null) // self-contained for runtime-specific only
.SetPublishTrimmed(PublishAot)
Expand All @@ -117,7 +117,7 @@ void PublishCompiler(string? runtimeId)

void GenerateCompilerRuntimeSpecificBundle(string runtimeId)
{
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject(configuration: Configuration);
var compilerProject = Solution.Cesium_Compiler.GetEvaluatedProperties(Configuration);

if (!SkipCaches && !NeedPackageCompilerRuntimeSpecificBundle(compilerProject, runtimeId))
{
Expand Down Expand Up @@ -153,7 +153,7 @@ void GenerateCompilerRuntimeSpecificBundle(string runtimeId)

void GenerateCompilerNuPkg()
{
var compilerProject = Solution.Cesium_Compiler.GetMSBuildProject(configuration: Configuration);
var compilerProject = Solution.Cesium_Compiler.GetEvaluatedProperties(Configuration);

if (!SkipCaches && !NeedPackageCompilerNuPkg(compilerProject))
{
Expand Down Expand Up @@ -272,9 +272,10 @@ IEnumerable<IPackageFile> GetPhysicalFiles(string publishDirectory, IEnumerable<
return expression.ToString();
}

private IEnumerable<(string Id, string Version)> GetCompilerBundlePackages(Project project)
private IEnumerable<(string Id, string Version)> GetCompilerBundlePackages(ProjectProperties project)
{
var json = DotNet($"list \"{project.FullPath}\" package --include-transitive --format json", logOutput: false)
var projectPath = project.GetEvaluatedProperty("MSBuildProjectFullPath");
var json = DotNet($"list \"{projectPath}\" package --include-transitive --format json", logOutput: false)
.StdToText();

using var doc = JsonDocument.Parse(json);
Expand All @@ -299,7 +300,7 @@ IEnumerable<IPackageFile> GetPhysicalFiles(string publishDirectory, IEnumerable<
return allPackages;
}

private string GetCompilerBundleLicenseExpression(Project project)
private string GetCompilerBundleLicenseExpression(ProjectProperties project)
{
var licenseExpressions = GetLicenseExpressions().Distinct().OrderBy(x => x).ToList();
var result = string.Join(" AND ", licenseExpressions);
Expand Down Expand Up @@ -342,7 +343,7 @@ IEnumerable<string> GetLicenseExpressions()
}
}

private IEnumerable<string> GetCompilerBundleCopyrightStatements(Project project)
private IEnumerable<string> GetCompilerBundleCopyrightStatements(ProjectProperties project)
{
yield return "2021-2026 Cesium contributors <https://github.com/ForNeVeR/Cesium>";

Expand All @@ -354,10 +355,10 @@ private IEnumerable<string> GetCompilerBundleCopyrightStatements(Project project
}
}

AbsolutePath GetCompilerRuntimePublishFolder(Project compilerProject, string? runtimeId) =>
AbsolutePath GetCompilerRuntimePublishFolder(ProjectProperties compilerProject, string? runtimeId) =>
Path.Combine(
compilerProject.GetProperty("ArtifactsPath").EvaluatedValue,
compilerProject.GetProperty("ArtifactsPublishOutputName").EvaluatedValue,
compilerProject.GetEvaluatedProperty("ArtifactsPath"),
compilerProject.GetEvaluatedProperty("ArtifactsPublishOutputName"),
Solution.Cesium_Compiler.Name,
GetRuntimeArtifactFolder(Configuration, compilerProject.GetVersion(), runtimeId));

Expand All @@ -373,15 +374,15 @@ static string GetCompilerNuGetPackageFileName(string version) =>
static string GetCompilerRuntimeSpecificBundleFileName(string version, string runtimeId) =>
$"{_compilerBundlePackageName}.{runtimeId}.{version}.zip";

bool NeedPublishCompilerBundle(Project compiler, string? runtimeId)
bool NeedPublishCompilerBundle(ProjectProperties compiler, string? runtimeId)
{
var folder = GetCompilerRuntimePublishFolder(compiler, runtimeId);

return !Directory.Exists(folder)
|| Directory.GetFiles(folder, "Cesium.Compiler*").Length == 0;
}

bool NeedPackageCompilerRuntimeSpecificBundle(Project compiler, string runtimeId)
bool NeedPackageCompilerRuntimeSpecificBundle(ProjectProperties compiler, string runtimeId)
{
var version = compiler.GetVersion();
var packageDirectory = compiler.GetPackageOutputPath();
Expand All @@ -392,7 +393,7 @@ bool NeedPackageCompilerRuntimeSpecificBundle(Project compiler, string runtimeId
GetCompilerRuntimePublishFolder(compiler, runtimeId));
}

bool NeedPackageCompilerNuPkg(Project compiler)
bool NeedPackageCompilerNuPkg(ProjectProperties compiler)
{
var version = compiler.GetVersion();
var packageDirectory = compiler.GetPackageOutputPath();
Expand Down
2 changes: 1 addition & 1 deletion build/Build.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ void ExecuteTests(Project project)
{
DotNetTest(_ => _
.SetConfiguration(Configuration)
.SetProjectFile(project.GetMSBuildProject().ProjectFileLocation.File));
.SetProjectFile(project.Path));
}
}
45 changes: 37 additions & 8 deletions build/ProjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
// SPDX-FileCopyrightText: 2025 Cesium contributors <https://github.com/ForNeVeR/Cesium>
// SPDX-FileCopyrightText: 2025-2026 Cesium contributors <https://github.com/ForNeVeR/Cesium>
//
// SPDX-License-Identifier: MIT

using System.Collections.Generic;
using Microsoft.Build.Evaluation;
using System.Linq;
using System.Text.Json;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using ProjectProperties = System.Collections.Generic.IReadOnlyDictionary<string, string>;

public static class ProjectExtensions
{
public static IReadOnlyCollection<string> GetRuntimeIds(this Project project)
public static ProjectProperties GetEvaluatedProperties(this Project project, string configuration)
{
// Use the selected SDK's MSBuild and NuGet assemblies instead of loading them into NUKE.
string[] propertyNames =
[
"MSBuildProjectFullPath",
"VersionPrefix",
"PackageOutputPath",
"ArtifactsPath",
"ArtifactsPublishOutputName",
"RuntimeIdentifiers",
"PublishDir"
];
var properties = string.Join(",", propertyNames);
var output = DotNet(
$"msbuild {project.Path} -nologo -property:Configuration={configuration} -getProperty:{properties}",
logOutput: false)
.StdToText();

using var document = JsonDocument.Parse(output);
return document.RootElement.GetProperty("Properties").EnumerateObject()
.ToDictionary(property => property.Name, property => property.Value.GetString()!);
}

public static IReadOnlyCollection<string> GetRuntimeIds(this ProjectProperties project)
{
return project.GetEvaluatedProperty("RuntimeIdentifiers").Split(";");
}

public static string GetVersion(this Project project)
public static string GetVersion(this ProjectProperties project)
{
return project.GetEvaluatedProperty("VersionPrefix");
}

public static string GetPackageOutputPath(this Project project)
public static string GetPackageOutputPath(this ProjectProperties project)
{
return project.GetEvaluatedProperty("PackageOutputPath");
}

public static string GetPublishDirectory(this Project project)
public static string GetPublishDirectory(this ProjectProperties project)
{
return project.GetEvaluatedProperty("PublishDir");
}

public static string GetEvaluatedProperty(this Project project, string name)
public static string GetEvaluatedProperty(this ProjectProperties project, string name)
{
return project.GetProperty(name).EvaluatedValue;
return project[name];
}
}
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "10.0.204",
"rollForward": "disable",
"version": "10.0.403",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
Loading