/// <summary> /// Publishes an ASP.NET 4.x project to the given GCE <seealso cref="Instance"/>. /// </summary> /// <param name="project">The project to deploy.</param> /// <param name="targetInstance">The instance to deploy.</param> /// <param name="credentials">The Windows credentials to use to deploy to the <paramref name="targetInstance"/>.</param> /// <param name="targetDeployPath">The Name or Path of the Website or App to publish</param> /// <param name="configuration">The name of the configuration to publish.</param> public async Task <bool> PublishProjectAsync( IParsedDteProject project, Instance targetInstance, WindowsInstanceCredentials credentials, string targetDeployPath, string configuration) { // Ensure NuGet packages are restored. project.Project.DTE.Solution.SolutionBuild.BuildProject(configuration, project.Project.UniqueName, true); string msbuildPath = VsVersionUtils.ToolsPathProvider.GetMsbuildPath(); MSBuildTarget target; switch (project.ProjectType) { case KnownProjectTypes.WebApplication: target = new MSBuildTarget("WebPublish"); break; default: target = new MSBuildTarget("Publish"); break; } var parameters = new object[] { '"' + project.FullPath + '"', target, new MSBuildProperty("Configuration", configuration), new MSBuildProperty("WebPublishMethod", "MSDeploy"), new MSBuildProperty("MSDeployPublishMethod", "WMSVC"), new MSBuildProperty("MSDeployServiceURL", targetInstance.GetPublishUrl()), new MSBuildProperty("DeployIisAppPath", targetDeployPath), new MSBuildProperty("UserName", credentials.User), new MSBuildProperty("Password", credentials.Password), new MSBuildProperty("AllowUntrustedCertificate", "True") }; string publishMessage = string.Format(Resources.GcePublishProgressMessage, targetInstance.Name); using (StatusbarHelper.FreezeText(publishMessage)) using (StatusbarHelper.ShowDeployAnimation()) using (ShellUtils.SetShellUIBusy()) { return(await ProcessService.RunCommandAsync( msbuildPath, string.Join(" ", parameters), GcpOutputWindow.OutputLine)); } }
/// <summary> /// Publishes an ASP.NET 4.x project to the given GCE <seealso cref="Instance"/>. /// </summary> /// <param name="project">The project to deploy.</param> /// <param name="targetInstance">The instance to deploy.</param> /// <param name="credentials">The Windows credentials to use to deploy to the <paramref name="targetInstance"/>.</param> /// <param name="targetDeployPath">The Name or Path of the Website or App to publish</param> /// <param name="configuration">The name of the configuration to publish.</param> public async Task <bool> PublishProjectAsync( IParsedDteProject project, Instance targetInstance, WindowsInstanceCredentials credentials, string targetDeployPath, string configuration) { await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync(); ShellUtils.SaveAllFiles(); // Ensure NuGet packages are restored. project.Project.DTE.Solution.SolutionBuild.BuildProject(configuration, project.Project.UniqueName, true); await GcpOutputWindow.ClearAsync(); await GcpOutputWindow.OutputLineAsync(string.Format(Resources.GcePublishStepStartMessage, project.Name)); await GcpOutputWindow.ActivateAsync(); string msbuildPath = VsVersionUtils.ToolsPathProvider.GetMsbuildPath(); MSBuildTarget target; switch (project.ProjectType) { case KnownProjectTypes.WebApplication: target = new MSBuildTarget("WebPublish"); break; default: target = new MSBuildTarget("Publish"); break; } var parameters = new object[] { '"' + project.FullPath + '"', target, new MSBuildProperty("Configuration", configuration), new MSBuildProperty("WebPublishMethod", "MSDeploy"), new MSBuildProperty("MSDeployPublishMethod", "WMSVC"), new MSBuildProperty("MSDeployServiceURL", targetInstance.GetPublishUrl()), new MSBuildProperty("DeployIisAppPath", targetDeployPath), new MSBuildProperty("UserName", credentials.User), new MSBuildProperty("Password", credentials.Password), new MSBuildProperty("AllowUntrustedCertificate", "True"), new MSBuildProperty("GoogleCloudExtensionBuild", "True") }; string publishMessage = string.Format(Resources.GcePublishProgressMessage, targetInstance.Name); using (await StatusbarHelper.FreezeTextAsync(publishMessage)) using (await StatusbarHelper.ShowDeployAnimationAsync()) using (await ShellUtils.SetShellUIBusyAsync()) { string msBuildParameters = string.Join(" ", parameters); bool result = await ProcessService.RunCommandAsync( msbuildPath, msBuildParameters, GcpOutputWindow.OutputLineAsync); if (result) { return(true); } await TaskScheduler.Default; // An initial failure is common, retry. await Task.Delay(TimeSpan.FromMilliseconds(100)); return(await ProcessService.RunCommandAsync( msbuildPath, msBuildParameters, GcpOutputWindow.OutputLineAsync)); } }