如何使用roslyn编译器创建解决方案,项目,文档物理文件?

时间:2018-10-11 09:37:13

标签: c# .net-core roslyn roslyn-code-analysis

基本上,我必须使用.net核心中的Addhocworkspace生成它。 我已经尝试了很多,但是看不到任何项目解决方案或物理文档文件。

代码:

var adHoc = new AdhocWorkspace();    
var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Create(), "/ProjectSolution.sln");
adHoc.AddSolution(solutionInfo);

var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "project", "project.csproj", "C#");
adHoc.AddProject(projectInfo);

SourceText sourceText = SourceText.From("class Program { static void Main() { System.Console.WriteLine(\"HelloWorld\"); } }");

                //var documentInfo = DocumentInfo.Create(DocumentId.CreateNewId(projectInfo.Id), "project.cs");
adHoc.AddDocument(projectInfo.Id, "Program.cs", sourceText);

//  adHoc.TryApplyChanges(adHoc.CurrentSolution);
var generator = SyntaxGenerator.GetGenerator(adHoc, "C#");

0 个答案:

没有答案