罗斯林添加文件到项目 [英] Roslyn Add a document to a project
本文介绍了罗斯林添加文件到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跑罗斯林CTP2
我在尝试一个新的HTML文件添加到项目
I am attempting to add a new html file to a project
IWorkspace workspace = Workspace.LoadSolution("MySolution.sln");
var originalSolution = workspace.CurrentSolution;
ISolution newSolution = originalSolution;
newSolution.GetProject(newSolution.ProjectIds.First())
.AddDocument("index.html", "<html></html>");
workspace.ApplyChanges(originalSolution, newSolution);
这导致没有改变被写入。我想获得新的HTML文件出现在VS
This results in no changes being written. I am trying to get the new html file to appear in VS
推荐答案
有两个问题在这里:
- 罗斯林
ISolution
,的IProject
和的IDocument
对象是不可改变的,因此要想看到改变,你需要创建一个新的ISolution
的修改,然后调用Workspace.ApplyChanges()
。 - 在罗斯林,
的IDocument
只创建的对象的文件传递给编译器。说这句话的另一种方式是东西都是编译
的ItemGroup
在项目文件中的一部分。对于其他文件(包括HTML文件),你应该使用像IVsSolution
正常的Visual Studio界面。
- Roslyn
ISolution
,IProject
, andIDocument
objects are immutable, so in order to see changes you would need to create a newISolution
with the changes, then callWorkspace.ApplyChanges()
. - In Roslyn,
IDocument
objects are only created for files that are passed to the compiler. Another way of saying this is things that are part of theCompile
ItemGroup
in the project file. For other files (including html files), you should use the normal Visual Studio interfaces likeIVsSolution
.
这篇关于罗斯林添加文件到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文