// disclaimer: visual studio doesn't support adding dependent file under linked file // so no dependent transformed config under linked app.config in designer private static void CreateConfigFiles(Project project, ProjectItem projectItem) { string appConfigName = projectItem.Name; var buildConfigurationNames = project.GetBuildConfigurationNames(); var projectFileIsDirty = false; // get app.config directory. new transform config will be created there. //var path = projectItem.GetFullPath(); string path = null; if (projectItem.IsLink()) { path = Directory.GetParent(projectItem.ContainingProject.FullName).FullName; } else { path = Directory.GetParent(projectItem.GetFullPath()).FullName; } foreach (var buildConfigurationName in buildConfigurationNames) { var dependentConfig = GetTransformConfigName(appConfigName, buildConfigurationName); var dependentConfigFullPath = Path.Combine(path, dependentConfig); // check if config file exist if (!FileWrapper.Exists(dependentConfigFullPath)) { using (var file = FileWrapper.AppendText(dependentConfigFullPath)) { file.Write(DependencyConfigContent); } projectFileIsDirty = true; projectItem.ProjectItems.AddFromFile(dependentConfigFullPath); //project.ProjectItems.AddFromFile(dependentConfigFullPath); } } }
// disclaimer: visual studio doesn't support adding dependent file under linked file // so no dependent transformed config under linked app.config in designer private static void CreateConfigFiles(Project project, ProjectItem projectItem) { var appConfigName = projectItem.Name; var buildConfigurationNames = project.GetBuildConfigurationNames(); // get app.config directory. new transform config will be created there. string path; if (projectItem.IsLink()) { path = Directory.GetParent(projectItem.ContainingProject.FullName).FullName; } else { path = Directory.GetParent(projectItem.GetFullPath()).FullName; } foreach (var buildConfigurationName in buildConfigurationNames) { var dependentConfig = GetTransformConfigName(appConfigName, buildConfigurationName); var dependentConfigFullPath = Path.Combine(path, dependentConfig); // check if config file exist if (FileWrapper.Exists(dependentConfigFullPath)) { VsService.OutputLine($"File {dependentConfig} already exists"); } else { using (var file = FileWrapper.AppendText(dependentConfigFullPath)) { file.Write(DependencyConfigContent); } VsService.OutputLine($"File {dependentConfig} was added"); } // add it to project file anyway, in case it was deleted just from project file projectItem.ProjectItems.AddFromFile(dependentConfigFullPath); } }