我自己调用CSharpCodeProvider编译aspx文件在vs2003下是正常的但在vs2005下就编译通过不了,估计是vs2005编译aspx的方式改变了,各位有什么高招吗?
代码如下:
StringBuilder _mess=new StringBuilder();
CodeDomProvider codeProvider = null;
codeProvider = new CSharpCodeProvider();
ICodeCompiler compiler = codeProvider.CreateCompiler();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.CompilerOptions = "/target:library /optimize";
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.OutputAssembly = @"C:\test\bin\test.dll";
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
string[] _files = new string[2];
_files[0] = @"C:\test\test.aspx";
_files[1] = @"C:\test\test.aspx.cs";
CompilerResults results = compiler.CompileAssemblyFromFileBatch(compilerParams, _files);
if (results.Errors.Count > 0)
{
foreach (CompilerError error in results.Errors)
{
_mess.Append("Compine Error:" + error.ErrorText);
}
}
代码如下:
StringBuilder _mess=new StringBuilder();
CodeDomProvider codeProvider = null;
codeProvider = new CSharpCodeProvider();
ICodeCompiler compiler = codeProvider.CreateCompiler();
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.CompilerOptions = "/target:library /optimize";
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.OutputAssembly = @"C:\test\bin\test.dll";
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
string[] _files = new string[2];
_files[0] = @"C:\test\test.aspx";
_files[1] = @"C:\test\test.aspx.cs";
CompilerResults results = compiler.CompileAssemblyFromFileBatch(compilerParams, _files);
if (results.Errors.Count > 0)
{
foreach (CompilerError error in results.Errors)
{
_mess.Append("Compine Error:" + error.ErrorText);
}
}
Compine Error:命名空间并不直接包含诸如字段或方法之类的成员
这两个错误