I am writing a C # Roslyn and CodeFix parser that will create a new file .txtbased on some variables if it does not exist and it will add a new line if that happens. The analyzer and file creation work fine using the following code in RegisterCodeFixAction:
var proj = document.Project.AddAdditionalDocument("file.txt",
"text content");
return proj.Solution;
Although, when I try to search the collection of projects AdditionalDocuments, it is empty, even if the file was created earlier (and the project is saved, if that matters).
var doc = document.Project.AdditionalDocuments.FirstOrDefault(x =>
x.Name == "file.txt");
I tried to add a new file as simple Documentinstead AdditionalDocument, but file.txtcreated as a source code file file.cs, not as .txt, but for some reason, I can find it as file.csin a collection Project.Documents.
, CodeFixProvider ?