// Static Constructor. static PSVersionInfo() { s_psVersionTable = new PSVersionHashTable(StringComparer.OrdinalIgnoreCase); Assembly currentAssembly = typeof(PSVersionInfo).Assembly; ProductVersion = currentAssembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; // Get 'GitCommitId' and 'PSVersion' from the 'productVersion' assembly attribute. // // The strings can be one of the following format examples: // when powershell is built from a commit: // productVersion = '6.0.0-beta.7 Commits: 29 SHA: 52c6b...' convert to GitCommitId = 'v6.0.0-beta.7-29-g52c6b...' // PSVersion = '6.0.0-beta.7' // when powershell is built from a release tag: // productVersion = '6.0.0-beta.7 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0-beta.7' // PSVersion = '6.0.0-beta.7' // when powershell is built from a release tag for RTM: // productVersion = '6.0.0 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0' // PSVersion = '6.0.0' string rawGitCommitId; string mainVersion = ProductVersion.Substring(0, ProductVersion.IndexOf(' ')); if (ProductVersion.Contains(" Commits: ")) { rawGitCommitId = ProductVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g"); } else { rawGitCommitId = mainVersion; } s_psSemVersion = new SemanticVersion(mainVersion); s_psVersion = (Version)s_psSemVersion; s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion; s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue; s_psVersionTable[PSGitCommitIdName] = rawGitCommitId; s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV61Version, s_psV62Version, s_psV7Version, s_psV71Version, s_psVersion }; s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion); s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion; s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion(); s_psVersionTable[PSPlatformName] = Environment.OSVersion.Platform.ToString(); s_psVersionTable[PSOSName] = Runtime.InteropServices.RuntimeInformation.OSDescription; }