罗斯林添加文件到项目 [英] Roslyn Add a document to a project

查看:121
本文介绍了罗斯林添加文件到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑罗斯林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

推荐答案

有两个问题在这里:


  1. 罗斯林 ISolution 的IProject 的IDocument 对象是不可改变的,因此要想看到改变,你需要创建一个新的 ISolution 的修改,然后调用 Workspace.ApplyChanges()

  2. 在罗斯林,的IDocument 只创建的对象的文件传递给编译器。说这句话的另一种方式是东西都是编译 的ItemGroup 在项目文件中的一部分。对于其他文件(包括HTML文件),你应该使用像 IVsSolution 正常的Visual Studio界面。

  1. Roslyn ISolution, IProject, and IDocument objects are immutable, so in order to see changes you would need to create a new ISolution with the changes, then call Workspace.ApplyChanges().
  2. 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 the Compile ItemGroup in the project file. For other files (including html files), you should use the normal Visual Studio interfaces like IVsSolution.

这篇关于罗斯林添加文件到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆