Is there a way to compile files automatically in the right order. Seems like 'CompileAssemblyFromFile' do not care about dependencies before compiling. Way around ?

public bClass 
{
   public aClass FieldName; //Trows error not aClass type not found
}

Compile Order

1. bClass.css
2. aClass.cs
有帮助吗?

解决方案

It works for me in either order:

var pro = new CSharpCodeProvider();
var assem = pro.CompileAssemblyFromFile(new CompilerParameters(), "path/to/bClass.cs", "path/to/aClass.cs");
// or
var assem = pro.CompileAssemblyFromFile(new CompilerParameters(), "path/to/aClass.cs", "path/to/bClass.cs");

aClass.cs:

public class aClass 
{
}

bClass.cs:

public class bClass 
{
   public aClass FieldName;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top