Skip to content

Commit 9ceac5b

Browse files
angularsenclaude
andauthored
🔨Split build scripts for NanoFramework (#1627)
This refactoring improves the build system's cross-platform compatibility by separating Windows-only NanoFramework builds from the main dotnet CLI builds. Changes: - Split Start-Build into Start-Build (dotnet CLI) and Start-BuildNanoFramework (MSBuild) - Split Start-PackNugets into Start-PackNugets (dotnet pack) and Start-PackNugetsNanoFramework (NuGet.exe) - Made Start-Build and Start-PackNugets use only dotnet CLI for cross-platform support - Updated build.ps1 to conditionally call NanoFramework functions with -IncludeNanoFramework flag - Added Visual Studio/MSBuild prerequisite checks to NanoFramework functions - Export new functions from build-functions module This allows the main build to work on any platform with .NET SDK installed, while NanoFramework builds remain optional and Windows-only. 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <[email protected]>
1 parent ff9acd7 commit 9ceac5b

File tree

2 files changed

+73
-38
lines changed

2 files changed

+73
-38
lines changed

Build/build-functions.psm1

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,52 @@ function Update-GeneratedCode {
3838
write-host -foreground blue "Generate code...END`n"
3939
}
4040

41-
function Start-Build([boolean] $IncludeNanoFramework = $false) {
42-
write-host -foreground blue "Start-Build...`n---"
41+
function Start-Build {
42+
write-host -foreground blue "Start-Build (dotnet CLI)...`n---"
4343

44-
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.msbuild.log"
45-
46-
dotnet build --configuration Release /p:ContinuousIntegrationBuild=true "$root\UnitsNet.slnx" $fileLoggerArg
44+
# Use dotnet CLI for all main projects - cross-platform compatible
45+
dotnet build --configuration Release /p:ContinuousIntegrationBuild=true "$root\UnitsNet.slnx"
4746
if ($lastexitcode -ne 0) { exit 1 }
4847

49-
if (-not $IncludeNanoFramework)
50-
{
51-
write-host -foreground yellow "Skipping .NET nanoFramework build."
48+
write-host -foreground blue "Start-Build...END`n"
49+
}
50+
51+
function Start-BuildNanoFramework {
52+
write-host -foreground blue "Start-BuildNanoFramework (MSBuild)...`n---"
53+
54+
# Check prerequisites
55+
if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) {
56+
write-host -foreground red "ERROR: Cannot build .NET nanoFramework - MSBuild not found."
57+
write-host -foreground yellow "Install Visual Studio with .NET desktop development workload to build NanoFramework projects."
58+
exit 1
5259
}
53-
else
54-
{
55-
# Check if MSBuild is available before attempting NanoFramework build
56-
if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) {
57-
write-host -foreground yellow "Cannot build .NET nanoFramework - MSBuild not found. Install Visual Studio to build NanoFramework projects."
58-
write-host -foreground yellow "Continuing with main build only..."
59-
}
60-
else {
61-
write-host -foreground green "Build .NET nanoFramework."
62-
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log"
63-
64-
# msbuild does not auto-restore nugets for this project type
65-
& "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln"
66-
67-
# now build
68-
& "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg
69-
if ($lastexitcode -ne 0) { exit 1 }
70-
}
60+
61+
if (-not (Test-Path $nuget)) {
62+
write-host -foreground red "ERROR: NuGet.exe not found at $nuget"
63+
write-host -foreground yellow "Run init.ps1 to download required tools."
64+
exit 1
7165
}
7266

73-
write-host -foreground blue "Start-Build...END`n"
67+
write-host -foreground green "Building .NET nanoFramework projects..."
68+
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log"
69+
70+
# msbuild does not auto-restore nugets for this project type
71+
write-host "Restoring NuGet packages for NanoFramework..."
72+
& "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln"
73+
if ($lastexitcode -ne 0) {
74+
write-host -foreground red "Failed to restore NuGet packages for NanoFramework"
75+
exit 1
76+
}
77+
78+
# Build with MSBuild
79+
write-host "Building NanoFramework solution..."
80+
& "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg
81+
if ($lastexitcode -ne 0) {
82+
write-host -foreground red "Failed to build NanoFramework solution"
83+
exit 1
84+
}
85+
86+
write-host -foreground blue "Start-BuildNanoFramework...END`n"
7487
}
7588

7689
function Start-Tests {
@@ -112,14 +125,14 @@ function Start-Tests {
112125
write-host -foreground blue "Run tests...END`n"
113126
}
114127

115-
function Start-PackNugets([boolean] $IncludeNanoFramework = $false) {
128+
function Start-PackNugets {
116129
$projectPaths = @(
117130
"UnitsNet\UnitsNet.csproj",
118131
"UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj",
119132
"UnitsNet.NumberExtensions\UnitsNet.NumberExtensions.csproj"
120133
)
121134

122-
write-host -foreground blue "Pack nugets...`n---"
135+
write-host -foreground blue "Pack nugets (dotnet CLI)...`n---"
123136
foreach ($projectPath in $projectPaths) {
124137
dotnet pack --configuration Release `
125138
--no-build `
@@ -130,14 +143,23 @@ function Start-PackNugets([boolean] $IncludeNanoFramework = $false) {
130143
if ($lastexitcode -ne 0) { exit 1 }
131144
}
132145

133-
if (-not $IncludeNanoFramework) {
134-
write-host -foreground yellow "Skipping nanoFramework nuget pack."
135-
} else {
136-
write-host -foreground yellow "nanoFramework project not yet supported by dotnet CLI, using nuget.exe instead"
137-
Invoke-BuildNanoNugets
146+
write-host -foreground blue "Pack nugets...END`n"
147+
}
148+
149+
function Start-PackNugetsNanoFramework {
150+
write-host -foreground blue "Pack NanoFramework nugets (NuGet.exe)...`n---"
151+
152+
# Check prerequisites
153+
if (-not (Test-Path $nuget)) {
154+
write-host -foreground red "ERROR: NuGet.exe not found at $nuget"
155+
write-host -foreground yellow "Run init.ps1 to download required tools."
156+
exit 1
138157
}
139158

140-
write-host -foreground blue "Pack nugets...END`n"
159+
write-host -foreground yellow "nanoFramework project not yet supported by dotnet CLI, using nuget.exe instead"
160+
Invoke-BuildNanoNugets
161+
162+
write-host -foreground blue "Pack NanoFramework nugets...END`n"
141163
}
142164

143165
function Compress-ArtifactsAsZip {
@@ -160,4 +182,4 @@ function Compress-ArtifactsAsZip {
160182
write-host -foreground blue "Zip artifacts...END`n"
161183
}
162184

163-
export-modulemember -function Start-NugetRestore, Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Start-SignedBuild, Start-Tests, Start-PackNugets, Compress-ArtifactsAsZip
185+
export-modulemember -function Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Start-BuildNanoFramework, Start-Tests, Start-PackNugets, Start-PackNugetsNanoFramework, Compress-ArtifactsAsZip

Build/build.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ try {
2828

2929
Remove-ArtifactsDir
3030
Update-GeneratedCode
31-
Start-Build -IncludeNanoFramework $IncludeNanoFramework
31+
32+
# Build main projects with dotnet CLI (cross-platform)
33+
Start-Build
3234
Start-Tests
33-
Start-PackNugets -IncludeNanoFramework $IncludeNanoFramework
35+
Start-PackNugets
36+
37+
# Build NanoFramework if requested (Windows-only, requires Visual Studio)
38+
if ($IncludeNanoFramework) {
39+
write-host -foreground cyan "`n===== Building NanoFramework projects (requires Visual Studio) =====`n"
40+
Start-BuildNanoFramework
41+
Start-PackNugetsNanoFramework
42+
}
43+
else {
44+
write-host -foreground yellow "`nSkipping NanoFramework build. Use -IncludeNanoFramework flag to build NanoFramework projects.`n"
45+
}
46+
3447
Compress-ArtifactsAsZip
3548
}
3649
catch {

0 commit comments

Comments
 (0)