Question

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
Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top