void UpdateAppConfig(TargetFramework newFramework) { // When changing the target framework, update any existing app.config // Also, for applications (not libraries), create an app.config is it is required for the target framework bool createAppConfig = newFramework.RequiresAppConfigEntry && (Project.OutputType != OutputType.Library && Project.OutputType != OutputType.Module); string appConfigFileName = CompilableProject.GetAppConfigFile(Project, createAppConfig); if (appConfigFileName == null) return; using (FakeXmlViewContent xml = new FakeXmlViewContent(appConfigFileName)) { if (xml.Document != null) { XElement configuration = xml.Document.Root; XElement startup = configuration.Element("startup"); if (startup == null) { startup = new XElement("startup"); if (configuration.HasElements && configuration.Elements().First().Name == "configSections") { // <configSections> must be first element configuration.Elements().First().AddAfterSelf(startup); } else { startup = configuration.AddFirstWithIndentation(startup); } } XElement supportedRuntime = startup.Element("supportedRuntime"); if (supportedRuntime == null) { supportedRuntime = startup.AddFirstWithIndentation(new XElement("supportedRuntime")); } supportedRuntime.SetAttributeValue("version", newFramework.SupportedRuntimeVersion); supportedRuntime.SetAttributeValue("sku", newFramework.SupportedSku); } } }
void UpdateAppConfig(TargetFramework newFramework) { // When changing the target framework, update any existing app.config // Also, for applications (not libraries), create an app.config is it is required for the target framework bool createAppConfig = newFramework.RequiresAppConfigEntry && (this.OutputType != OutputType.Library && this.OutputType != OutputType.Module); string appConfigFileName = Path.Combine(this.Directory, "app.config"); if (!File.Exists(appConfigFileName)) { if (createAppConfig) { File.WriteAllText(appConfigFileName, "<?xml version=\"1.0\"?>" + Environment.NewLine + "<configuration>" + Environment.NewLine + "</configuration>"); } else { return; } } if (!IsFileInProject(appConfigFileName)) { FileProjectItem fpi = new FileProjectItem(this, ItemType.None, "app.config"); ProjectService.AddProjectItem(this, fpi); FileService.FireFileCreated(appConfigFileName, false); ProjectBrowserPad.RefreshViewAsync(); } using (FakeXmlViewContent xml = new FakeXmlViewContent(appConfigFileName)) { if (xml.Document != null) { XElement configuration = xml.Document.Root; XElement startup = configuration.Element("startup"); if (startup == null) { startup = new XElement("startup"); configuration.AddFirst(startup); } XElement supportedRuntime = startup.Element("supportedRuntime"); if (supportedRuntime == null) { supportedRuntime = new XElement("supportedRuntime"); startup.AddFirst(supportedRuntime); } supportedRuntime.SetAttributeValue("version", newFramework.SupportedRuntimeVersion); supportedRuntime.SetAttributeValue("sku", newFramework.SupportedSku); } } }