diff --git a/.gitignore b/.gitignore index b19f5bd8d..088159d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ docs/_repo/ docs/metadata/ *.zip +# Generated build info file +src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs + # quickbuild.exe /VersionGeneratingLogs/ QLogs diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 375b2dce7..2e5038fca 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -20,6 +20,7 @@ $script:IsCIBuild = $env:APPVEYOR -ne $null $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows $script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`"" $script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease") +$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Host", "BuildInfo", "BuildInfo.cs") if ($PSVersionTable.PSEdition -ne "Core") { Add-Type -Assembly System.IO.Compression.FileSystem @@ -142,6 +143,51 @@ task TestPowerShellApi -If { !$script:IsUnix } { exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj } } +task CreateBuildInfo -Before Build { + $buildVersion = "" + $buildOrigin = "" + + # Set build info fields on build platforms + if ($env:APPVEYOR) + { + $buildVersion = $env:APPVEYOR_BUILD_VERSION + $buildOrigin = if ($env:CI) { "AppVeyor CI" } else { "AppVeyor" } + } + elseif ($env:TF_BUILD) + { + $psd1Path = [System.IO.Path]::Combine($PSScriptRoot, "module", "PowerShellEditorServices", "PowerShellEditorServices.psd1") + $buildVersion = (Import-PowerShellDataFile -LiteralPath $psd1Path).Version + $buildOrigin = "VSTS" + } + + # Allow override of build info fields (except date) + if ($env:PSES_BUILD_VERSION) + { + $buildVersion = $env:PSES_BUILD_VERSION + } + + if ($env:PSES_BUILD_ORIGIN) + { + $buildOrigin = $env:PSES_BUILD_ORIGIN + } + + [string]$buildTime = [datetime]::Now.ToString("s", [System.Globalization.CultureInfo]::InvariantCulture) + + $buildInfoContents = @" +namespace Microsoft.PowerShell.EditorServices.Host +{ + public static class BuildInfo + { + public const string BuildVersion = "$buildVersion"; + public const string BuildOrigin = "$buildOrigin"; + public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime"); + } +} +"@ + + Set-Content -LiteralPath $script:BuildInfoPath -Value $buildInfoContents -Force +} + task Build { exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -f netstandard1.6 } if (!$script:IsUnix) { @@ -208,6 +254,7 @@ task LayoutModule -After Build { New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\netstandard1.6\publish\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ + Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\netstandard1.6\publish\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ 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 { if (!$script:IsUnix) { Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\net451\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop + Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\net451\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\UnixConsoleEcho.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ - Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\publish\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ } # Copy Third Party Notices.txt to module folder diff --git a/module/PowerShellEditorServices/Start-EditorServices.ps1 b/module/PowerShellEditorServices/Start-EditorServices.ps1 index c84ad537a..9d3970adf 100644 --- a/module/PowerShellEditorServices/Start-EditorServices.ps1 +++ b/module/PowerShellEditorServices/Start-EditorServices.ps1 @@ -243,6 +243,9 @@ function Set-NamedPipeMode { } } +LogSection "Console Encoding" +Log $OutputEncoding + # Add BundledModulesPath to $env:PSModulePath if ($BundledModulesPath) { $env:PSModulePath = $env:PSModulePath.TrimEnd([System.IO.Path]::PathSeparator) + [System.IO.Path]::PathSeparator + $BundledModulesPath diff --git a/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs new file mode 100644 index 000000000..181a42589 --- /dev/null +++ b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs @@ -0,0 +1,9 @@ +namespace Microsoft.PowerShell.EditorServices.Host +{ + public static class BuildInfo + { + public const string BuildVersion = ""; + public const string BuildOrigin = ""; + public static readonly System.DateTime? BuildTime = null; + } +} diff --git a/src/PowerShellEditorServices.Host/EditorServicesHost.cs b/src/PowerShellEditorServices.Host/EditorServicesHost.cs index 324590877..0d1f7e8e4 100644 --- a/src/PowerShellEditorServices.Host/EditorServicesHost.cs +++ b/src/PowerShellEditorServices.Host/EditorServicesHost.cs @@ -19,6 +19,7 @@ using System.Management.Automation.Runspaces; using System.Reflection; using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace Microsoft.PowerShell.EditorServices.Host { @@ -140,39 +141,38 @@ public void StartLogging(string logFilePath, LogLevel logLevel) .Build(); #if CoreCLR - FileVersionInfo fileVersionInfo = - FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location); - - // TODO #278: Need the correct dependency package for this to work correctly - //string osVersionString = RuntimeInformation.OSDescription; - //string processArchitecture = RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "64-bit" : "32-bit"; - //string osArchitecture = RuntimeInformation.OSArchitecture == Architecture.X64 ? "64-bit" : "32-bit"; + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location); #else - FileVersionInfo fileVersionInfo = - FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location); - string osVersionString = Environment.OSVersion.VersionString; - string processArchitecture = Environment.Is64BitProcess ? "64-bit" : "32-bit"; - string osArchitecture = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit"; + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location); #endif - string newLine = Environment.NewLine; + string osVersion = RuntimeInformation.OSDescription; - this.logger.Write( - LogLevel.Normal, - string.Format( - $"PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (pid {Process.GetCurrentProcess().Id})..." + newLine + newLine + - " Host application details:" + newLine + newLine + - $" Name: {this.hostDetails.Name}" + newLine + - $" ProfileId: {this.hostDetails.ProfileId}" + newLine + - $" Version: {this.hostDetails.Version}" + newLine + -#if !CoreCLR - $" Arch: {processArchitecture}" + newLine + newLine + - " Operating system details:" + newLine + newLine + - $" Version: {osVersionString}" + newLine + - $" Arch: {osArchitecture}")); -#else - "")); -#endif + string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? ""; + + string logHeader = $@" +PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (PID {Process.GetCurrentProcess().Id} + + Host application details: + + Name: {this.hostDetails.Name} + Version: {this.hostDetails.Version} + ProfileId: {this.hostDetails.ProfileId} + Arch: {RuntimeInformation.OSArchitecture} + + Operating system details: + + Version: {osVersion} + Arch: {RuntimeInformation.OSArchitecture} + + Build information: + + Version: {BuildInfo.BuildVersion} + Origin: {BuildInfo.BuildOrigin} + Date: {buildTime} +"; + + this.logger.Write(LogLevel.Normal, logHeader); } /// diff --git a/src/PowerShellEditorServices/Console/ConsoleReadLine.cs b/src/PowerShellEditorServices/Console/ConsoleReadLine.cs index a3da640c7..7c518a718 100644 --- a/src/PowerShellEditorServices/Console/ConsoleReadLine.cs +++ b/src/PowerShellEditorServices/Console/ConsoleReadLine.cs @@ -29,8 +29,6 @@ internal class ConsoleReadLine #region Constructors static ConsoleReadLine() { - // Maybe we should just include the RuntimeInformation package for FullCLR? - #if CoreCLR if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { s_consoleProxy = new WindowsConsoleOperations(); @@ -38,9 +36,6 @@ static ConsoleReadLine() } s_consoleProxy = new UnixConsoleOperations(); - #else - s_consoleProxy = new WindowsConsoleOperations(); - #endif } public ConsoleReadLine(PowerShellContext powerShellContext) diff --git a/src/PowerShellEditorServices/Language/LanguageService.cs b/src/PowerShellEditorServices/Language/LanguageService.cs index e30c00b8a..f15e05bff 100644 --- a/src/PowerShellEditorServices/Language/LanguageService.cs +++ b/src/PowerShellEditorServices/Language/LanguageService.cs @@ -325,14 +325,10 @@ public async Task FindReferencesOfSymbol( // We want to look for references first in referenced files, hence we use ordered dictionary // TODO: File system case-sensitivity is based on filesystem not OS, but OS is a much cheaper heuristic -#if CoreCLR - // The RuntimeInformation.IsOSPlatform is not supported in .NET Framework var fileMap = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? new OrderedDictionary() : new OrderedDictionary(StringComparer.OrdinalIgnoreCase); -#else - var fileMap = new OrderedDictionary(StringComparer.OrdinalIgnoreCase); -#endif + foreach (ScriptFile file in referencedFiles) { fileMap.Add(file.FilePath, file); diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 1fbf922e9..d5060ae8f 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -65,6 +65,8 @@ + + diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index 12bfae3a4..0a7c5a77b 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -10,10 +10,7 @@ using System.IO; using System.Security; using System.Text; - -#if CoreCLR using System.Runtime.InteropServices; -#endif namespace Microsoft.PowerShell.EditorServices { @@ -498,12 +495,11 @@ private string ResolveRelativeScriptPath(string baseFilePath, string relativePat /// A file-scheme URI string with the drive colon unescaped. private static string UnescapeDriveColon(string fileUri) { -#if CoreCLR if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return fileUri; } -#endif + // Check here that we have something like "file:///C%3A/" as a prefix (caller must check the file:// part) if (!(fileUri[7] == '/' && char.IsLetter(fileUri[8]) &&