よろしくお願いします。
現在こちらのコードでpsファイルをコンパイルしようとしていますが、
プリプロセッサ ディレクティブが必要です。
単一行コメントか行の終わりが必要ですとエラーがでてしまい、
コンパイルされません。
改善方法や、他にプログラムからコンパイルする方法があれば教えていただきたいです。
よろしくお願いします。
C#
1 FileInfo sourceFile = new FileInfo(fileName); 2 3 CodeDomProvider provider = null; 4 5 // Select the code provider based on the input file extension. 6 if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".PS") 7 { 8 provider = CodeDomProvider.CreateProvider("CSharp"); 9 } 10 11 12 String exeName = String.Format(@"{0}\{1}.tmp", 13 System.Environment.CurrentDirectory, 14 sourceFile.Name.Replace(".", "_")); 15 16 CompilerParameters cp = new CompilerParameters(); 17 18 // Generate an executable instead of 19 // a class library. 20 cp.GenerateExecutable = true; 21 22 // Specify the assembly file name to generate. 23 cp.OutputAssembly = exeName; 24 25 // Save the assembly as a physical file. 26 cp.GenerateInMemory = false; 27 28 // Set whether to treat all warnings as errors. 29 cp.TreatWarningsAsErrors = false; 30 31 // Invoke compilation of the source file. 32 CompilerResults cr = provider.CompileAssemblyFromFile(cp, 33 fileName); 34 35 if (cr.Errors.Count > 0) 36 { 37 //エラーがあるときは出力する 38 foreach (System.CodeDom.Compiler.CompilerError compErr in cr.Errors) 39 { 40 Console.WriteLine("FileName:{0}", compErr.FileName); 41 Console.WriteLine("Line:{0}", compErr.Line); 42 Console.WriteLine("Column:{0}", compErr.Column); 43 Console.WriteLine("ErrorNumber:{0}", compErr.ErrorNumber); 44 Console.WriteLine("ErrorText:{0}", compErr.ErrorText); 45 } 46 MessageBox.Show("Error"); 47 } 48 else 49 { 50 MessageBox.Show("Success"); 51 }
エラーコード
FileName:d:\Projects\shader_works\shader_works\shader_works\bin\Debug\map.ps
Line:1
Column:2
ErrorNumber:CS1024
ErrorText:プリプロセッサ ディレクティブが必要です。
FileName:d:\Projects\shader_works\shader_works\shader_works\bin\Debug\map.ps
Line:1
Column:9
ErrorNumber:CS1025
ErrorText:単一行コメントか行の終わりが必要です。
回答1件
あなたの回答
tips
プレビュー