1+ $assemblyPath = " ..\src\shared\GeneralAssemblyInfo.cs" ;
2+ $defaultVersion = " 1.0.0.0" ;
3+ $nugetPath = " ../nuget" ;
4+ $data = (" ..\src\AggregatedGenericResultMessage\AggregatedGenericResultMessage.csproj" );
5+ $forceCustomPackVersion = $args [0 ];
6+
7+ <#
8+ . SYNOPSIS
9+ A brief description of the Get-CurrentAssemblyVersion function.
10+
11+ . DESCRIPTION
12+ Get current assembly version
13+
14+ . EXAMPLE
15+ PS C:\> Get-CurrentAssemblyVersion
16+
17+ . NOTES
18+ Additional information about the function.
19+ #>
20+ function Get-CurrentAssemblyVersion
21+ {
22+ [OutputType ([string ])]
23+ param ()
24+
25+ $assemblyInfo = (Get-Content $assemblyPath );
26+ $asVersion = ($assemblyInfo -match ' AssemblyVersion\(".*"\)' );
27+ $asVersion = $asVersion -split (' "' );
28+ $asVersion = $asVersion [1 ];
29+
30+ return $asVersion ;
31+ }
32+
33+ <#
34+ . SYNOPSIS
35+ A brief description of the Build-And-Pack-BuildPack function.
36+
37+ . DESCRIPTION
38+ Build project and pack as package (u pkg)
39+
40+ . PARAMETER packVersion
41+ Package/Build version
42+
43+ . PARAMETER currentVersion
44+ A description of the currentVersion parameter.
45+
46+ . EXAMPLE
47+ PS C:\> Build-And-Pack-BuildPack -packVersion 'Value1'
48+
49+ . NOTES
50+ Additional information about the function.
51+ #>
52+ function Set-BuildAndPack
53+ {
54+ [CmdletBinding ()]
55+ [OutputType ([bool ])]
56+ param
57+ (
58+ [Parameter (Mandatory = $true )]
59+ [string ]$packVersion ,
60+ [string ]$currentVersion
61+ )
62+
63+ try
64+ {
65+ Write-Host " Project restore '$ ( $_ ) '!" - ForegroundColor Green;
66+ dotnet restore $ ($_ );
67+
68+ Write-Host " Build in Release '$ ( $_ ) '!" - ForegroundColor Green;
69+ $buildResult = dotnet build $ ($_ ) -- source https:// api.nuget.org/ v3/ index.json - c Release / p:AssemblyVersion= $packVersion / p:AssemblyFileVersion= $packVersion / p:AssemblyInformationalVersion= $packVersion ;
70+ if ($LASTEXITCODE -ne 0 )
71+ {
72+ Set-VersionAssembly - packVersion $currentVersion ;
73+ Write-Host $buildResult ;
74+
75+ return $false ;
76+ }
77+
78+ Write-Host " Pack in Release '$ ( $_ ) '!" - ForegroundColor Green;
79+ dotnet pack $ ($_ ) - p:PackageVersion= $packVersion -- no- build - c Release -- output $nugetPath ;
80+
81+ return $true ;
82+ }
83+ catch
84+ {
85+ Write-Host - foregroundcolor Red " An error occurred: $_ "
86+
87+ return $false ;
88+ }
89+ }
90+
91+ <#
92+ . SYNOPSIS
93+ A brief description of the Get-TimeStamp function.
94+
95+ . DESCRIPTION
96+ Get time stamp version
97+
98+ . EXAMPLE
99+ PS C:\> Get-TimeStamp
100+
101+ . NOTES
102+ Additional information about the function.
103+ #>
104+ function Get-TimeStamp
105+ {
106+ [CmdletBinding ()]
107+ [OutputType ([int ])]
108+ param ()
109+
110+ $current = [System.DateTime ]::Now;
111+ $end = [System.DateTime ]::Now.Date;
112+ $diff = (New-TimeSpan - Start $current - End $end ).TotalSeconds / 10 ;
113+ $timeSec = If ($diff -le 0 ) { $diff * -1 }
114+ Else { $diff };
115+
116+ return [int ]$timeSec ;
117+ }
118+
119+ <#
120+ . SYNOPSIS
121+ A brief description of the Set-VersionAssembly function.
122+
123+ . DESCRIPTION
124+ Set current version in assembly file
125+
126+ . PARAMETER packVersion
127+ A description of the packVersion parameter.
128+
129+ . EXAMPLE
130+ PS C:\> Set-VersionAssembly -packVersion 'Value1'
131+
132+ . NOTES
133+ Additional information about the function.
134+ #>
135+ function Set-VersionAssembly
136+ {
137+ [CmdletBinding ()]
138+ [OutputType ([void ])]
139+ param
140+ (
141+ [Parameter (Mandatory = $true )]
142+ [string ]$packVersion
143+ )
144+ $NewVersion = ' AssemblyVersion("' + $packVersion + ' ")' ;
145+ $NewFileVersion = ' AssemblyFileVersion("' + $packVersion + ' ")' ;
146+ $NewAssemblyInformationalVersion = ' AssemblyInformationalVersion("' + $packVersion + ' ")' ;
147+
148+ (Get-Content $assemblyPath - encoding utf8) |
149+ % { $_ -replace ' AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' , $NewVersion } |
150+ % { $_ -replace ' AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' , $NewFileVersion } |
151+ % { $_ -replace ' AssemblyInformationalVersion\("[0-9x]+(\.([0-9x]+|\*)){1,3}"\)' , $NewAssemblyInformationalVersion } |
152+ Set-Content $assemblyPath - encoding utf8
153+ }
154+
155+ <#
156+ . SYNOPSIS
157+ A brief description of the Exec-TestSolution function.
158+
159+ . DESCRIPTION
160+ Execute solution test
161+
162+ . EXAMPLE
163+ PS C:\> Exec-TestSolution
164+
165+ . NOTES
166+ Additional information about the function.
167+ #>
168+ function Exec-TestSolution
169+ {
170+ [CmdletBinding ()]
171+ [OutputType ([bool ])]
172+ param ()
173+
174+ # Merge all streams into stdout
175+ $result = dotnet test " ..\src\tests\InfoResultTests\InfoResultTests.csproj" * > & 1
176+
177+ # Evaluate success/failure
178+ if ($LASTEXITCODE -eq 0 )
179+ {
180+ return $true ;
181+ }
182+ else
183+ {
184+ $errorString = $result -join [System.Environment ]::NewLine;
185+ Write-Host - foregroundcolor Red " An error occurred: $errorString " ;
186+
187+ return $false ;
188+ }
189+ }
190+
191+ Write-Host " Init test solution...`n " - ForegroundColor Green;
192+ $testExec = Exec- TestSolution;
193+ If ($testExec -eq $true )
194+ {
195+ Write-Host " Path to pack: '$nugetPath '`n " - ForegroundColor Green;
196+
197+ $currentVersion = " " ;
198+ If ($forceCustomPackVersion -eq $null -or $forceCustomPackVersion -eq " " ) { $currentVersion = Get-CurrentAssemblyVersion ; }
199+ Else { $currentVersion = $forceCustomPackVersion ; }
200+
201+ $directoryInfo = Get-ChildItem $nugetPath | Where-Object { $_.Name -match ' [a-z]*.1.0.0.nupkg$' } | Measure-Object ;
202+ If ($defaultVersion -eq $currentVersion -and $directoryInfo.count -eq 0 )
203+ {
204+ Set-VersionAssembly - packVersion $currentVersion ;
205+
206+ $data | ForEach-Object {
207+ $buildResult = Set-BuildAndPack - packVersion $currentVersion ;
208+ If ($buildResult -eq $false -or $buildResult -ccontains $false )
209+ {
210+ exit ;
211+ }
212+ }
213+
214+ Write-Host " `n Pack executed with success with version: $currentVersion !" - ForegroundColor Green;
215+
216+ exit ;
217+ }
218+ Else
219+ {
220+ $finalVersion = " " ;
221+ If ($forceCustomPackVersion -eq $null -or $forceCustomPackVersion -eq " " )
222+ {
223+ $versArray = $currentVersion.Split (' .' );
224+ $finalVersion = $versArray [0 ].ToString() + " ." + $versArray [1 ].ToString() + " ." + (([int ]$versArray [2 ]) + 1 ).ToString() + " ." + (Get-TimeStamp ).ToString();
225+ }
226+ Else { $finalVersion = $forceCustomPackVersion ; }
227+
228+ Set-VersionAssembly - packVersion $finalVersion ;
229+
230+ $data | ForEach-Object {
231+ $buildResult = Set-BuildAndPack - packVersion $finalVersion - currentVersion $currentVersion ;
232+ If ($buildResult -eq $false -or $buildResult -ccontains $false )
233+ {
234+ exit ;
235+ }
236+ }
237+
238+ Write-Host " `n Pack executed with success with version: $finalVersion !" - ForegroundColor Green;
239+
240+ exit ;
241+ }
242+ }
243+ Else { exit ; }
0 commit comments