Exemplo n.º 1
0
        public static void CheckVersion(PSCmdlet cmdlet)
        {
            // do we need to check versions. Is the environment variable set?
            var pnppowershellUpdatecheck = Environment.GetEnvironmentVariable("PNPPOWERSHELL_UPDATECHECK");

            if (!string.IsNullOrEmpty(pnppowershellUpdatecheck))
            {
                if (pnppowershellUpdatecheck.ToLower() == "off" || pnppowershellUpdatecheck.ToLower() == "false")
                {
                    VersionChecked = true;
                }
            }

            try
            {
                if (!VersionChecked)
                {
                    var assembly       = Assembly.GetExecutingAssembly();
                    var versionInfo    = FileVersionInfo.GetVersionInfo(assembly.Location);
                    var productVersion = versionInfo.ProductVersion;
                    var isNightly      = productVersion.Contains("-");

                    var onlineVersion = GetAvailableVersion(isNightly);

                    if (IsNewer(onlineVersion) && cmdlet != null)
                    {
                        var updateMessage = $"\nA newer version of PnP PowerShell is available: {onlineVersion}.\n\nUse 'Update-Module -Name PnP.PowerShell {(isNightly ? "-AllowPrerelease" : "")}' to update.\nUse 'Get-PnPChangeLog {(!isNightly ? $"-Release {onlineVersion}" : "-Nightly")}' to list changes.\n\nYou can turn this check off by setting the 'PNPPOWERSHELL_UPDATECHECK' environment variable to 'Off'.\n";
                        CmdletMessageWriter.WriteFormattedWarning(cmdlet, updateMessage);
                    }
                    VersionChecked = true;
                }
            }
            catch (Exception)
            { }
        }
Exemplo n.º 2
0
        public static void CheckVersion(PSCmdlet cmdlet)
        {
            // do we need to check versions. Is the environment variable set?
            var pnppowershellUpdatecheck = Environment.GetEnvironmentVariable("PNPPOWERSHELL_UPDATECHECK");

            if (!string.IsNullOrEmpty(pnppowershellUpdatecheck))
            {
                if (pnppowershellUpdatecheck.ToLower() == "off" || pnppowershellUpdatecheck.ToLower() == "false")
                {
                    VersionChecked = true;
                }
            }

            try
            {
                if (!VersionChecked)
                {
                    var onlineVersion = GetAvailableVersion();

                    if (isNewer(onlineVersion) && cmdlet != null)
                    {
#if DEBUG
                        var updateMessage = $"\nA newer version of PnP PowerShell is available: {onlineVersion}.\n\nUse 'Update-Module -Name PnP.PowerShell -AllowPrerelease' to update.\n\nYou can turn this check off by setting the 'PNPPOWERSHELL_UPDATECHECK' environment variable to 'Off'.\n";
#else
                        var updateMessage = $"\nA newer version of PnP PowerShell is available: {onlineVersion}.\n\nUse 'Update-Module -Name PnP.PowerShell' to update.\n\nYou can turn this check off by setting the 'PNPPOWERSHELL_UPDATECHECK' environment variable to 'Off'.\n";
#endif
                        CmdletMessageWriter.WriteFormattedWarning(cmdlet, updateMessage);
                    }
                    VersionChecked = true;
                }
            }
            catch (Exception)
            { }
        }