/// <summary> /// Try to load a NuGetUpgrader from config settings. /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader. /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured. /// </isConfigured> /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns> /// </summary> public static bool TryCreate( ITracer tracer, PhysicalFileSystem fileSystem, LocalGVFSConfig gvfsConfig, ICredentialStore credentialStore, bool dryRun, bool noVerify, out NuGetUpgrader nuGetUpgrader, out bool isConfigured, out string error) { NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, gvfsConfig); nuGetUpgrader = null; isConfigured = false; if (!upgraderConfig.TryLoad(out error)) { nuGetUpgrader = null; return(false); } if (!(isConfigured = upgraderConfig.IsConfigured(out error))) { return(false); } // At this point, we have determined that the system is set up to use // the NuGetUpgrader if (!upgraderConfig.IsReady(out error)) { return(false); } nuGetUpgrader = new NuGetUpgrader( ProcessHelper.GetCurrentProcessVersion(), tracer, fileSystem, dryRun, noVerify, upgraderConfig, ProductUpgraderInfo.GetAssetDownloadsPath(), credentialStore); return(true); }
public override bool TryRunInstaller(InstallActionWrapper installActionWrapper, out string error) { string localError = null; int installerExitCode; bool installSuccessful = true; using (ITracer activity = this.tracer.StartActivity(nameof(this.TryRunInstaller), EventLevel.Informational)) { InstallActionInfo currentInstallAction = null; try { string platformKey = InstallManifest.WindowsPlatformKey; if (!this.TryRecursivelyDeleteInstallerDirectory(out error)) { return(false); } if (!this.noVerify) { if (!this.nuGetFeed.VerifyPackage(this.DownloadedPackagePath)) { error = "Package signature validation failed. Check the upgrade logs for more details."; activity.RelatedError(error); this.fileSystem.DeleteFile(this.DownloadedPackagePath); return(false); } } this.UnzipPackage(); this.installManifest = InstallManifest.FromJsonFile(Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName, InstallManifestFileName)); if (!this.installManifest.PlatformInstallManifests.TryGetValue(platformKey, out InstallManifestPlatform platformInstallManifest) || platformInstallManifest == null) { activity.RelatedError($"Extracted InstallManifest from JSON, but there was no entry for {platformKey}."); error = $"No entry in the manifest for the current platform ({platformKey}). Please verify the upgrade package."; return(false); } activity.RelatedInfo($"Extracted InstallManifest from JSON. InstallActions: {platformInstallManifest.InstallActions.Count}"); foreach (InstallActionInfo entry in platformInstallManifest.InstallActions) { currentInstallAction = entry; string installerPath = Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName, entry.InstallerRelativePath); string args = entry.Args ?? string.Empty; // Replace tokens on args string processedArgs = NuGetUpgrader.ReplaceArgTokens(args, this.UpgradeInstanceId, ProductUpgraderInfo.GetLogDirectoryPath()); activity.RelatedInfo( "Running install action: Name: {0}, Version: {1}, InstallerPath: {2} RawArgs: {3}, ProcessedArgs: {4}", entry.Name, entry.Version, installerPath, args, processedArgs); string progressMessage = string.IsNullOrWhiteSpace(entry.Version) ? $"Running {entry.Name}" : $"Running {entry.Name} (version {entry.Version})"; installActionWrapper( () => { if (!this.dryRun) { this.RunInstaller(installerPath, processedArgs, out installerExitCode, out localError); } else { // We add a sleep here to ensure // the message for this install // action is written to the // console. Even though the // message is written with a delay // of 0, the messages are not // always written out. If / when // we can ensure that the message // is written out to console, then // we can remove this sleep. Thread.Sleep(1500); installerExitCode = 0; } installSuccessful = installerExitCode == 0; return(installSuccessful); }, progressMessage); if (!installSuccessful) { break; } } } catch (Exception ex) { localError = ex.Message; installSuccessful = false; } if (!installSuccessful) { string installActionName = string.IsNullOrEmpty(currentInstallAction?.Name) ? "installer" : currentInstallAction.Name; error = string.IsNullOrEmpty(localError) ? $"The {installActionName} failed, but no error message was provided by the failing command." : $"The {installActionName} failed with the following error: {localError}"; activity.RelatedError($"Could not complete all install actions. The following error was encountered: {error}"); return(false); } else { activity.RelatedInfo($"Install actions completed successfully."); error = null; return(true); } } }
/// <summary> /// Try to load a NuGetUpgrader from config settings. /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader. /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured. /// </isConfigured> /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns> /// </summary> public static bool TryCreate( ITracer tracer, PhysicalFileSystem fileSystem, bool dryRun, bool noVerify, out NuGetUpgrader nuGetUpgrader, out bool isConfigured, out string error) { NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, new LocalGVFSConfig()); nuGetUpgrader = null; isConfigured = false; if (!upgraderConfig.TryLoad(out error)) { nuGetUpgrader = null; return(false); } if (!(isConfigured = upgraderConfig.IsConfigured(out error))) { return(false); } // At this point, we have determined that the system is set up to use // the NuGetUpgrader if (!upgraderConfig.IsReady(out error)) { return(false); } string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath(); if (string.IsNullOrEmpty(gitBinPath)) { error = $"NuGetUpgrader: Unable to locate git installation. Ensure git is installed and try again."; return(false); } string authUrl; if (!TryCreateAzDevOrgUrlFromPackageFeedUrl(upgraderConfig.FeedUrl, out authUrl, out error)) { return(false); } if (!TryGetPersonalAccessToken( gitBinPath, authUrl, tracer, out string token, out string getPatError)) { error = $"NuGetUpgrader was not able to acquire Personal Access Token to access NuGet feed. Error: {getPatError}"; tracer.RelatedError(error); return(false); } nuGetUpgrader = new NuGetUpgrader( ProcessHelper.GetCurrentProcessVersion(), tracer, fileSystem, dryRun, noVerify, upgraderConfig, ProductUpgraderInfo.GetAssetDownloadsPath(), token); return(true); }