public override bool Execute() { Log.LogMessage(MessageImportance.Low, $"Configuring the following project for use with IIS: '{PublishDir}'"); XDocument webConfigXml = null; string webConfigPath = Path.Combine(PublishDir, "web.config"); webConfigPath = Path.GetFullPath(webConfigPath); if (File.Exists(webConfigPath)) { Log.LogMessage($"Updating web.config at '{webConfigPath}'"); try { webConfigXml = XDocument.Load(webConfigPath); } catch (XmlException e) { Log.LogWarning($"Cannot parse web.config as XML. A new web.config will be generated. Error Details : {e.Message}"); } } else { Log.LogMessage($"No web.config found. Creating '{webConfigPath}'"); } if (IsAzure) { Log.LogMessage("Configuring web.config for deployment to Azure"); } string outputFile = Path.GetFileName(TargetPath); XDocument transformedConfig = WebConfigTransform.Transform( webConfigXml, outputFile, IsAzure, UseAppHost, ExecutableExtension, AspNetCoreModuleName, AspNetCoreHostingModel, EnvironmentName, ProjectFullPath); // Telemetry transformedConfig = WebConfigTelemetry.AddTelemetry(transformedConfig, ProjectGuid, IgnoreProjectGuid, SolutionPath, ProjectFullPath); using (FileStream f = new FileStream(webConfigPath, FileMode.Create)) { transformedConfig.Save(f); } Log.LogMessage(MessageImportance.Low, "Configuring project completed successfully"); return(true); }
public override bool Execute() { Log.LogMessage(MessageImportance.Low, $"Configuring the following project for use with IIS: '{PublishDir}'"); XDocument webConfigXml = null; string webConfigPath = Path.Combine(PublishDir, "web.config"); if (File.Exists(webConfigPath)) { Log.LogMessage($"Updating web.config at '{webConfigPath}'"); try { webConfigXml = XDocument.Load(webConfigPath); } catch (XmlException) { } } else { Log.LogMessage($"No web.config found. Creating '{webConfigPath}'"); } if (IsAzure) { Log.LogMessage("Configuring web.config for deployment to Azure"); } string outputFile = Path.GetFileName(TargetPath); XDocument transformedConfig = WebConfigTransform.Transform(webConfigXml, outputFile, IsAzure, IsPortable); // Add the projectGuid to web.config if it is not present. transformedConfig = WebConfigTransform.AddProjectGuidToWebConfig(transformedConfig, ProjectGuid, IgnoreProjectGuid); using (FileStream f = new FileStream(webConfigPath, FileMode.Create)) { transformedConfig.Save(f); } Log.LogMessage(MessageImportance.Low, "Configuring project completed successfully"); return(true); }
public override bool Execute() { Log.LogMessage(MessageImportance.Low, $"Configuring the following project for use with IIS: '{PublishDir}'"); XDocument webConfigXml = null; // Initialize the publish web.config file with project web.config content if present. Else, clean the existing web.config in the // publish folder to make sure we have a consistent web.config update experience. string projectWebConfigPath = null; if (!string.IsNullOrEmpty(ProjectFullPath)) { projectWebConfigPath = Path.Combine(Path.GetDirectoryName(ProjectFullPath), "web.config"); } string publishWebConfigPath = Path.Combine(PublishDir, "web.config"); publishWebConfigPath = Path.GetFullPath(publishWebConfigPath); if (File.Exists(publishWebConfigPath)) { if (File.Exists(projectWebConfigPath)) { File.Copy(projectWebConfigPath, publishWebConfigPath, true); } else { File.WriteAllText(publishWebConfigPath, WebConfigTemplate.Template); } Log.LogMessage($"Updating web.config at '{publishWebConfigPath}'"); try { webConfigXml = XDocument.Load(publishWebConfigPath); } catch (XmlException e) { Log.LogWarning($"Cannot parse web.config as XML. A new web.config will be generated. Error Details : {e.Message}"); } } else { Log.LogMessage($"No web.config found. Creating '{publishWebConfigPath}'"); } if (IsAzure) { Log.LogMessage("Configuring web.config for deployment to Azure"); } string outputFile = Path.GetFileName(TargetPath); XDocument transformedConfig = WebConfigTransform.Transform( webConfigXml, outputFile, IsAzure, UseAppHost, ExecutableExtension, AspNetCoreModuleName, AspNetCoreHostingModel, EnvironmentName, ProjectFullPath); // Telemetry transformedConfig = WebConfigTelemetry.AddTelemetry(transformedConfig, ProjectGuid, IgnoreProjectGuid, SolutionPath, ProjectFullPath); using (FileStream f = new FileStream(publishWebConfigPath, FileMode.Create)) { transformedConfig.Save(f); } Log.LogMessage(MessageImportance.Low, "Configuring project completed successfully"); return(true); }