Public/Set-PCProjectVersion.ps1
|
<# .SYNOPSIS Sets the version of a project. .DESCRIPTION Writes a new version to the project's native version file. Auto-detects the project ecosystem unless overridden. .PARAMETER Version The new version to set (e.g., "1.2.3" or "v1.2.3"). .PARAMETER Path Project directory. Defaults to current directory. .EXAMPLE Set-PCProjectVersion -Version "1.3.0" # Updates the version in the current project's manifest .EXAMPLE Set-PCProjectVersion -Version "2.0.0" -Path C:\repos\MyModule #> function Set-PCProjectVersion { [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$Version, [Parameter()] [string]$Path = (Get-Location).Path ) # Validate version format $null = Get-SemanticVersion -Version $Version $projectType = Get-ProjectType -Path $Path if ($projectType.Type -eq 'Unknown') { throw "No recognized project type found in '$Path'" } $cleanVersion = $Version -replace '^v', '' if ($PSCmdlet.ShouldProcess($projectType.File, "Set version to $cleanVersion")) { Write-Verbose "Setting version to $cleanVersion in $($projectType.FileName)" Write-ProjectVersion -Version $cleanVersion -ProjectType $projectType Write-Verbose "Version updated successfully" } } |