写C#程序时,我们需要关注当前程序所需要的引用(Reference)。只有这些引用被添加进编译器,其在编译的时候才能够找到我们在程序中使用的程序集(Assembly)。
添加Reference
List<MetadataReference> references = new List<MetadataReference>()
{
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(MyCustomClass).Assembly.Location),
};
添加using
using可以在C#程序中手动添加,就如同我们平常学程序一样,但如果我们想要在语法树中添加using节点(通常用来作为默认的using),可以使用AddUsings();
root = root.AddUsings