Skip to content

Commit 15c37ec

Browse files
committed
Centralize the project's version too
Add help document to updateVersion.ps1
1 parent 6b670b4 commit 15c37ec

File tree

9 files changed

+50
-211
lines changed

9 files changed

+50
-211
lines changed

.pipelines/PSScriptAnalyzer-Official.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ extends:
6363
ob_outputDirectory: $(Build.SourcesDirectory)/out
6464
steps:
6565
- pwsh: |
66-
[xml]$xml = Get-Content Engine/Engine.csproj
67-
$version = $xml.SelectSingleNode(".//VersionPrefix")."#text"
66+
[xml]$xml = Get-Content ./Directory.Build.props
67+
$version = $xml.Project.PropertyGroup.ModuleVersion
6868
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$version"
6969
name: package
7070
displayName: Get version from project properties

Directory.Build.props

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<Project>
2+
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
23
<PropertyGroup>
4+
<ModuleVersion>1.22.0</ModuleVersion>
35
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
46
</PropertyGroup>
57
</Project>

Engine/Engine.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.22.0</VersionPrefix>
4+
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
55
<TargetFrameworks>net6;net462</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
7-
<AssemblyVersion>1.22.0</AssemblyVersion>
7+
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
88
<PackageId>Engine</PackageId>
99
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
1010
<LangVersion>9.0</LangVersion>

Engine/PSScriptAnalyzer.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
1111
RootModule = 'PSScriptAnalyzer.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.22.0'
14+
ModuleVersion = '{{ModuleVersion}}'
1515

1616
# ID used to uniquely identify this module
1717
GUID = 'd6245802-193d-4068-a631-8863a4342a18'

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.22.0</VersionPrefix>
4+
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
55
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
6-
<AssemblyVersion>1.22.0</AssemblyVersion>
6+
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
77
</PropertyGroup>
88

99
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

Rules/Rules.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.22.0</VersionPrefix>
4+
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
55
<TargetFrameworks>net6;net462</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
7-
<AssemblyVersion>1.22.0</AssemblyVersion>
7+
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
88
<PackageId>Rules</PackageId>
99
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
1010
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- Needed in order for Pluralize.NET DLL to appear in bin folder - https://github.com/NuGet/Home/issues/4488 -->

Utils/ReleaseMaker.psm1

-198
This file was deleted.

build.psm1

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ $analyzerName = "PSScriptAnalyzer"
77

88
function Get-AnalyzerVersion
99
{
10-
[xml]$xml = Get-Content $([io.path]::Combine($projectRoot,"Engine","Engine.csproj"))
11-
$xml.SelectSingleNode(".//VersionPrefix")."#text"
10+
[xml]$xml = Get-Content $([io.path]::Combine($projectRoot, "Directory.Build.props"))
11+
$xml.Project.PropertyGroup.ModuleVersion
1212
}
1313

1414
$analyzerVersion = Get-AnalyzerVersion
@@ -159,9 +159,15 @@ function Start-ScriptAnalyzerBuild
159159
throw "Not in solution root"
160160
}
161161

162+
# "Copy" the module file with the version placeholder replaced
163+
$manifestContent = Get-Content -LiteralPath "$projectRoot\Engine\PSScriptAnalyzer.psd1" -Raw
164+
$newManifestContent = $manifestContent -replace '{{ModuleVersion}}', $analyzerVersion
165+
Set-Content -LiteralPath "$script:destinationDir\PSScriptAnalyzer.psd1" -Encoding utf8 -Value $newManifestContent
166+
162167
$itemsToCopyCommon = @(
163-
"$projectRoot\Engine\PSScriptAnalyzer.psd1", "$projectRoot\Engine\PSScriptAnalyzer.psm1",
164-
"$projectRoot\Engine\ScriptAnalyzer.format.ps1xml", "$projectRoot\Engine\ScriptAnalyzer.types.ps1xml"
168+
"$projectRoot\Engine\PSScriptAnalyzer.psm1",
169+
"$projectRoot\Engine\ScriptAnalyzer.format.ps1xml",
170+
"$projectRoot\Engine\ScriptAnalyzer.types.ps1xml"
165171
)
166172

167173
switch ($PSVersion)

tools/updateVersion.ps1

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
param(
5+
[Parameter(Mandatory)]
6+
[semver]$Version,
7+
8+
[Parameter(Mandatory)]
9+
[string]$Changes
10+
)
11+
12+
git diff --staged --quiet --exit-code
13+
if ($LASTEXITCODE -ne 0) {
14+
throw "There are staged changes in the repository. Please commit or reset them before running this script."
15+
}
16+
17+
$Path = "Directory.Build.props"
18+
$f = Get-Content -Path $Path
19+
$f = $f -replace '^(?<prefix>\s+<ModuleVersion>)(.+)(?<suffix></ModuleVersion>)$', "`${prefix}${Version}`${suffix}"
20+
$f | Set-Content -Path $Path
21+
git add $Path
22+
23+
$Path = "docs/Cmdlets/PSScriptAnalyzer.md"
24+
$f = Get-Content -Path $Path
25+
$f = $f -replace '^(?<prefix>Help Version: )(.+)$', "`${prefix}${Version}"
26+
$f | Set-Content -Path $Path
27+
git add $Path
28+
29+
git commit --edit --message "v${Version}: $Changes"

0 commit comments

Comments
 (0)