我自己调用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);
                }
            }

解决方案 »

  1.   

    编译时报:Compine Error:原义说明符 @ 之后应为关键字、标识符或字符串
             Compine Error:命名空间并不直接包含诸如字段或方法之类的成员
    这两个错误
      

  2.   

    stest.aspx/test.aspx.cs这2个文件在普通的ASP.NET项目里能运行么?
      

  3.   

    以前在2003时只要把.cs文件编译成和aspx同名的.dll放在bin目录中就可运行的