Skip to content

Commit 4d9d155

Browse files
Joel BennettJoel Bennett
authored andcommitted
Update build to include setting the version
@dlwyatt if you don't like this I can revert this, but @JPRuskin is right that this is how I prefer to do it
1 parent 8335c04 commit 4d9d155

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,5 @@ pip-log.txt
215215
#Mr Developer
216216
.mr.developer.cfg
217217

218-
Output/
218+
# The default build.ps1 output folders
219+
[0-9]*\.[0-9]*\.[0-9]*/

Build.ps1

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
[CmdletBinding()]
2-
param($OutputDirectory = $("$PSScriptRoot\Output"), [switch]$Force)
2+
param(
3+
# A version number to update the output with (uses gitversion by default)
4+
$Version = $(gitversion -showvariable nugetversion),
35

6+
# The output folder (defaults to the version number)
7+
$OutputDirectory = $("$PSScriptRoot\$(($Version -split '[-+]',2)[0])"),
48

5-
Remove-Item $OutputDirectory -Recurse -Confirm:(!$Force)
9+
# If set, removes the output folder without prompting!
10+
[switch]$Force
11+
)
612

13+
$VersionPrefix, $VersionSuffix = $Version -split '[-+]', 2
714

8-
Copy-Item $PSScriptRoot\Module -Destination $OutputDirectory -recurse
15+
if (Test-Path $OutputDirectory) {
16+
Remove-Item $OutputDirectory -Recurse -Confirm:(!$Force)
17+
}
18+
19+
Copy-Item $PSScriptRoot\Module\PowerShellLogging -Destination $OutputDirectory -recurse
20+
Set-Content $OutputDirectory\PowerShellLogging.psd1 (
21+
(Get-Content $OutputDirectory\PowerShellLogging.psd1) -replace
22+
"(ModuleVersion\s+=\s+)'.*'", "`$1'$VersionPrefix'" -replace
23+
"(Prerelease\s+=\s+)'.*'", "`$1'$VersionSuffix'"
24+
)
25+
26+
dotnet build -c Release -p:VersionPrefix=$VersionPrefix -p:VersionSuffix=$VersionSuffix
927

10-
dotnet build -c Release
1128
Get-ChildItem bin/Release -recurse -filter *.dll |
12-
Move-Item -Destination $OutputDirectory\PowerShellLogging\
29+
Move-Item -Destination $OutputDirectory\

Module/PowerShellLogging/PowerShellLogging.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
PrivateData = @{
2020
PSData = @{
21+
Prerelease = ''
2122
LicenseUri = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
2223
ProjectUri = 'https://github.com/dlwyatt/PowerShellLoggingModule'
2324
ReleaseNotes = 'Added support for PowerShell 6 & 7

PowerShellLoggingModule.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
<!--<TargetFramework>net2.0</TargetFramework>-->
1414
<TargetFramework>netstandard2.0</TargetFramework>
1515
<ApplicationIcon />
16-
<PackageVersion>1.4.0</PackageVersion>
17-
<AssemblyVersion>1.0.0.0</AssemblyVersion>
16+
<VersionPrefix>1.4.0</VersionPrefix>
1817
<OutputType>Library</OutputType>
1918
<DebugType>embedded</DebugType>
2019
<StartupObject />

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,24 @@ Install-Module PowerShellLogging
2323
Compile your own copy
2424
====================
2525

26-
You can run `build.ps1` to assembly a copy in an `Output` folder,
27-
or you can just compile the assembly with:
26+
You can compile the assembly with:
2827

2928
```posh
3029
dotnet build -c Release
3130
```
3231

32+
To generate the full module, you can run the build script:
33+
34+
```posh
35+
.\build -Version $(gitversion -showvariable nugetversion)
36+
```
37+
38+
**Note:** this script builds into a version numbered folder in the module root.
39+
The expectation is that you have the source in a folder like `~\Projects\Modules\PowerShellLogging`
40+
where the parent folder can be added to your PSModulePath for testing purposes,
41+
so the build will end up in, e.g.: `~\Projects\Modules\PowerShellLogging\1.4.0`
42+
and the build script will update the metadata to make it all versioned properly!
43+
3344
Testing
3445
=======
3546

0 commit comments

Comments
 (0)