1+ <#
2+ . SYNOPSIS
3+ Evergine NuGet Packages generator script, (c) 2025 Evergine Team
4+ . DESCRIPTION
5+ This script generates NuGet packages for Evergine projects using dotnet pack.
6+ Supports both single and multiple project scenarios with flexible versioning.
7+ It's meant to have the same behavior when executed locally as when it's executed in a CI pipeline.
8+ . PARAMETER Version
9+ Direct version string to use for packages (used by add-ons)
10+ . PARAMETER Revision
11+ Revision number to append to date-based version (used by bindings)
12+ . PARAMETER Projects
13+ Array of .csproj paths to pack. For single project, can be a string.
14+ . PARAMETER OutputFolderBase
15+ Base folder for NuGet package output
16+ . PARAMETER BuildVerbosity
17+ dotnet verbosity level
18+ . PARAMETER BuildConfiguration
19+ Build configuration (Release, Debug, etc.)
20+ . PARAMETER IncludeSymbols
21+ Whether to include debug symbols in packages
22+ . PARAMETER SymbolsFormat
23+ Symbol package format: 'snupkg' (modern, default) or 'symbols.nupkg' (legacy)
24+ . PARAMETER HelpersPath
25+ Path to the Helpers.ps1 file. Defaults to Helpers.ps1 in the same directory as this script.
26+ . EXAMPLE
27+ # Binding style (date-based version with revision)
28+ .\Generate-NuGets-DotNet.ps1 -Revision 123 -Projects "SampleBinding\Evergine.Bindings.Sample\Evergine.Bindings.Sample.csproj"
29+ . EXAMPLE
30+ # Add-on style (direct version)
31+ .\Generate-NuGets-DotNet.ps1 -Version "3.4.22.288-local" -Projects @("Source\Evergine.SampleAddon\Evergine.SampleAddon.csproj", "Source\Evergine.SampleAddon.Editor\Evergine.SampleAddon.Editor.csproj")
32+ . EXAMPLE
33+ # Using custom helpers path
34+ .\Generate-NuGets-DotNet.ps1 -Revision 123 -Projects "test.csproj" -HelpersPath "C:\Scripts\MyHelpers.ps1"
35+ . EXAMPLE
36+ # Using legacy symbol format
37+ .\Generate-NuGets-DotNet.ps1 -Version "1.0.0" -Projects "test.csproj" -SymbolsFormat "symbols.nupkg"
38+ . LINK
39+ https://evergine.com/
40+ #>
41+
42+ param (
43+ [string ]$Version ,
44+ [string ]$Revision ,
45+ [Parameter (Mandatory = $true )]$Projects ,
46+ [string ]$OutputFolderBase = " nupkgs" ,
47+ [string ]$BuildVerbosity = " normal" ,
48+ [string ]$BuildConfiguration = " Release" ,
49+ [bool ]$IncludeSymbols = $false ,
50+ [ValidateSet (" snupkg" , " symbols.nupkg" )]
51+ [string ]$SymbolsFormat = " snupkg" ,
52+ [string ]$HelpersPath = " $PSScriptRoot \Helpers.ps1"
53+ )
54+
55+ # Import shared helper functions
56+ if (Test-Path $HelpersPath ) {
57+ . $HelpersPath
58+ }
59+ else {
60+ throw " Helpers file not found at: $HelpersPath . Please ensure Helpers.ps1 is available or specify correct path with -HelpersPath parameter."
61+ }
62+
63+ # Parameter validation
64+ if ([string ]::IsNullOrEmpty($Version ) -and [string ]::IsNullOrEmpty($Revision )) {
65+ throw " Either -Version or -Revision parameter must be provided"
66+ }
67+
68+ if (! [string ]::IsNullOrEmpty($Version ) -and ! [string ]::IsNullOrEmpty($Revision )) {
69+ throw " Cannot specify both -Version and -Revision parameters"
70+ }
71+
72+ if ($Projects -eq $null -or $Projects.Count -eq 0 -or ($Projects -is [array ] -and $Projects.Length -eq 0 )) {
73+ throw " Projects parameter cannot be empty"
74+ }
75+
76+ # Convert Projects to array if it's a single string
77+ if ($Projects -is [string ]) {
78+ $Projects = @ ($Projects )
79+ }
80+
81+ # Calculate version
82+ if (! [string ]::IsNullOrEmpty($Revision )) {
83+ $Version = " $ ( Get-Date - Format " yyyy.M.d" ) .$Revision "
84+ }
85+
86+ # Validate version format (NuGet semantic versioning)
87+ # See: https://docs.microsoft.com/en-us/nuget/concepts/package-versioning
88+ if ($Version -notmatch ' ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-([a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)(?:\.([a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?))*)?$' ) {
89+ throw " Invalid version format: '$Version '. NuGet version must follow semantic versioning (e.g., '1.0.0', '1.0.0-alpha', '1.0.0.123')."
90+ }
91+
92+ # Show variables
93+ $parameters = @ {
94+ " Version" = $Version
95+ " Projects" = ($Projects -join " , " )
96+ " BuildConfiguration" = $BuildConfiguration
97+ " BuildVerbosity" = $BuildVerbosity
98+ " OutputFolderBase" = $OutputFolderBase
99+ " IncludeSymbols" = $IncludeSymbols
100+ " SymbolsFormat" = $SymbolsFormat
101+ }
102+
103+ ShowVariables $parameters
104+
105+ # Create output folder
106+ $absoluteOutputFolder = CreateOutputFolder $OutputFolderBase
107+
108+ # Generate packages
109+ LogDebug " START packaging process"
110+
111+ foreach ($projectPath in $Projects ) {
112+ LogDebug " Processing project: $projectPath "
113+
114+ if (! (Test-Path $projectPath )) {
115+ throw " Project file not found: $projectPath "
116+ }
117+
118+ LogDebug " Packing $projectPath with dotnet"
119+
120+ # Build dotnet pack command with appropriate symbol format
121+ $packArgs = @ (
122+ " pack" , $projectPath ,
123+ " --verbosity" , $BuildVerbosity ,
124+ " --configuration" , $BuildConfiguration ,
125+ " --output" , $absoluteOutputFolder ,
126+ " -p:PackageVersion=$Version "
127+ )
128+
129+ if ($IncludeSymbols ) {
130+ if ($SymbolsFormat -eq " snupkg" ) {
131+ $packArgs += " -p:IncludeSymbols=true"
132+ $packArgs += " -p:SymbolPackageFormat=snupkg"
133+ }
134+ else {
135+ $packArgs += " -p:IncludeSymbols=true"
136+ }
137+ }
138+ else {
139+ $packArgs += " -p:IncludeSymbols=false"
140+ }
141+
142+ & dotnet @packArgs
143+
144+ if ($LASTEXITCODE -ne 0 ) {
145+ throw " dotnet pack failed for $projectPath "
146+ }
147+ }
148+
149+ LogDebug " END packaging process"
150+ LogDebug " NuGet packages generated in: $absoluteOutputFolder "
0 commit comments