protected override Project AddDocument(Project fromProject) => fromProject.AddAdditionalDocument( DocumentInfo.Name, Text, DocumentInfo.Folders, DocumentInfo.FilePath ).Project;
public static Project WithAdditionalDocs(this Project vbProject, IEnumerable <string> relativePaths) { string projDir = vbProject.GetDirectoryPath(); foreach (var fullPath in relativePaths.SelectMany(relativePath => GetAllLocaleResxFilePaths(projDir, relativePath))) { vbProject = vbProject.AddAdditionalDocument(Path.GetFileName(fullPath), SourceText.From(File.ReadAllText(fullPath)), filePath: fullPath).Project; } return(vbProject); }
// Local functions. static Project AddAdditionalDocument(Project project, string name, SourceText text) { TextDocument?additionalDocument = project.AdditionalDocuments.FirstOrDefault(doc => string.Equals(doc.Name, name, StringComparison.OrdinalIgnoreCase)); if (additionalDocument == null) { project = project.AddAdditionalDocument(name, text).Project; } return(project); }
public void AddContent(string path, string contents) { var contentFile = Path.Combine( Path.GetDirectoryName(_project.FilePath), path); if (File.Exists(contentFile)) { File.WriteAllText(contentFile, contents); } else { _project = _project .AddAdditionalDocument(Path.GetFileName(path), contents, filePath: Path.GetDirectoryName(path)) .Project; } }
private Task <Solution> CreateOrUpdateSolution(CodeFixContext context) { string content = SettingsProvider.ToFileContent(new AnalyzerSettings(true)); TextDocument existingDocument = context.Document.Project.AdditionalDocuments.FirstOrDefault( document => SettingsProvider.IsSettingsFile(document.FilePath)); Project project = context.Document.Project; if (existingDocument != null) { project = project.RemoveAdditionalDocument(existingDocument.Id); } TextDocument newDocument = project.AddAdditionalDocument(SettingsProvider.SettingsFileName, content); return(Task.FromResult(newDocument.Project.Solution)); }
public TextDocument AddAdditionalSuppressionDocumentToProject(Project project) { project.ThrowOnNull(nameof(project)); string suppressionFileName = project.AssemblyName + SuppressionFile.SuppressionFileExtension; string projectDir = Instance._fileSystemService.GetFileDirectory(project.FilePath); string suppressionFilePath = Path.Combine(projectDir, suppressionFileName); //Create new xml document and get its text var newXDocument = SuppressionFile.NewDocumentFromMessages(Enumerable.Empty <SuppressMessage>()); if (newXDocument == null) { return(null); } string docText = newXDocument.GetXDocumentStringWithDeclaration(); //Add file to project without applying changes to workspace return(project.AddAdditionalDocument(suppressionFileName, docText, filePath: suppressionFilePath)); }
public AnalyzedProject AddAdditionalDocument(string filenName, string text) { var document = Project.AddAdditionalDocument(filenName, text); return(new AnalyzedProject(Analyzer, document.Project)); }
public TextDocument AddAnalyzerSettings(Project project, string settings) { return(project.AddAdditionalDocument(AnalyzersSettings.AnalyzerFileName, SourceText.From(settings))); }