@@ -20,6 +20,7 @@ $script:IsCIBuild = $env:APPVEYOR -ne $null
2020$script :IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq " Core" -and ! $IsWindows
2121$script :TargetFrameworksParam = " /p:TargetFrameworks=\`" $ ( if (! $script :IsUnix ) { " net451;" }) netstandard1.6\`" "
2222$script :SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module ).Parameters.ContainsKey(" AllowPrerelease" )
23+ $script :BuildInfoPath = [System.IO.Path ]::Combine($PSScriptRoot , " src" , " PowerShellEditorServices.Host" , " BuildInfo" , " BuildInfo.cs" )
2324
2425if ($PSVersionTable.PSEdition -ne " Core" ) {
2526 Add-Type - Assembly System.IO.Compression.FileSystem
@@ -142,6 +143,51 @@ task TestPowerShellApi -If { !$script:IsUnix } {
142143 exec { & $script :dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
143144}
144145
146+ task CreateBuildInfo - Before Build {
147+ $buildVersion = " <development-build>"
148+ $buildOrigin = " <development>"
149+
150+ # Set build info fields on build platforms
151+ if ($env: APPVEYOR )
152+ {
153+ $buildVersion = $env: APPVEYOR_BUILD_VERSION
154+ $buildOrigin = if ($env: CI ) { " AppVeyor CI" } else { " AppVeyor" }
155+ }
156+ elseif ($env: TF_BUILD )
157+ {
158+ $psd1Path = [System.IO.Path ]::Combine($PSScriptRoot , " module" , " PowerShellEditorServices" , " PowerShellEditorServices.psd1" )
159+ $buildVersion = (Import-PowerShellDataFile - LiteralPath $psd1Path ).Version
160+ $buildOrigin = " VSTS"
161+ }
162+
163+ # Allow override of build info fields (except date)
164+ if ($env: PSES_BUILD_VERSION )
165+ {
166+ $buildVersion = $env: PSES_BUILD_VERSION
167+ }
168+
169+ if ($env: PSES_BUILD_ORIGIN )
170+ {
171+ $buildOrigin = $env: PSES_BUILD_ORIGIN
172+ }
173+
174+ [string ]$buildTime = [datetime ]::Now.ToString(" s" , [System.Globalization.CultureInfo ]::InvariantCulture)
175+
176+ $buildInfoContents = @"
177+ namespace Microsoft.PowerShell.EditorServices.Host
178+ {
179+ public static class BuildInfo
180+ {
181+ public const string BuildVersion = "$buildVersion ";
182+ public const string BuildOrigin = "$buildOrigin ";
183+ public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime ");
184+ }
185+ }
186+ "@
187+
188+ Set-Content - LiteralPath $script :BuildInfoPath - Value $buildInfoContents - Force
189+ }
190+
145191task Build {
146192 exec { & $script :dotnetExe publish - c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -f netstandard1.6 }
147193 if (! $script :IsUnix ) {
@@ -208,6 +254,7 @@ task LayoutModule -After Build {
208254 New-Item - Force $PSScriptRoot \module\PowerShellEditorServices\bin\Core - Type Directory | Out-Null
209255
210256 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices\bin\$Configuration \netstandard1.6 \publish\Serilog* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
257+ Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices\bin\$Configuration \netstandard1.6 \publish\System.Runtime.InteropServices.RuntimeInformation.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
211258
212259 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \netstandard1.6 \* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
213260 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \netstandard1.6 \UnixConsoleEcho.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Core\
@@ -216,11 +263,11 @@ task LayoutModule -After Build {
216263
217264 if (! $script :IsUnix ) {
218265 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices\bin\$Configuration \net451\Serilog* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop
266+ Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices\bin\$Configuration \net451\System.Runtime.InteropServices.RuntimeInformation.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
219267
220268 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\* - Filter Microsoft.PowerShell.EditorServices* .dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
221269 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\Newtonsoft.Json.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
222270 Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\UnixConsoleEcho.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
223- Copy-Item - Force - Path $PSScriptRoot \src\PowerShellEditorServices.Host\bin\$Configuration \net451\publish\System.Runtime.InteropServices.RuntimeInformation.dll - Destination $PSScriptRoot \module\PowerShellEditorServices\bin\Desktop\
224271 }
225272
226273 # Copy Third Party Notices.txt to module folder
0 commit comments