This should add a document.
public static void AddDoc() { var msBuild = MSBuildWorkspace.Create(); var sln = msBuild.OpenSolutionAsync (@"D:\PanNiebieski\Documents\Visual Studio 14\Projects\WebApplication1" + @"\WebApplication1.sln").Result; foreach (var p in sln.Projects) { p.AddDocument(Guid.NewGuid().ToString() + ".txt", "test"); var ok = msBuild.TryApplyChanges(sln); Console.WriteLine(p.Name + ":" + ok); } Console.ReadKey(); }
The TryApplyChanges method returns true so that the document is added. Again, when I check the solution, nothing of the sort exists. I have the same problem with adding project links.
The question is how can I save the changes, for example, adding a document to this project. I'm missing something. Many of the questions in StackOverflow about adding project links say this just doesn't work. Does the AddDocument method work?
This method says that this action is supported. I am embarrassed.

source share