日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何在Win界面上完成C#編譯

本文只是可以讓大家擺脫csc的約束,在Win界面上完成C#編譯編譯.

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:申請域名、網(wǎng)頁空間、營銷軟件、網(wǎng)站建設(shè)、福山網(wǎng)站維護(hù)、網(wǎng)站推廣。

在C#編譯過程中你必須以下面的步驟完成:

1.建立一個CSharpCodeProvider 實例(如果是使用Visual Basic則使用VBCodeProvider)

2.包含接口ICodeCompiler

3.提供CompilerParameters的參數(shù)

4.使用CompileAssemblyFromSource方法編譯。

5.運行CompilerResults

6.執(zhí)行C#編譯好的程序

編譯的代碼可以是寫在文本框中的字符串,當(dāng)然也可以源文件。

 
 
 
  1. private void button1_Click(object 
  2. sender, System.EventArgs e) 
  3. CSharpCodeProvider codeProvider = 
  4. new CSharpCodeProvider(); 
  5. // For Visual Basic Compiler try this : 
  6. //Microsoft.VisualBasic.VBCodeProvider 
  7. ICodeCompiler compiler = 
  8. codeProvider.CreateCompiler(); 
  9. CompilerParameters parameters = 
  10. new CompilerParameters(); 
  11. parameters.GenerateExecutable = true; 
  12. if (appName.Text == "") 
  13. System.Windows.Forms.MessageBox.Show(this, 
  14. "Application name cannot be empty"); 
  15. return ; 
  16. parameters.OutputAssembly = appName.
  17. Text.ToString(); 
  18. if (mainClass.Text.ToString() == "") 
  19. System.Windows.Forms.MessageBox.Show(this, 
  20. "Main Class Name cannot be empty"); 
  21. return ; 
  22. parameters.MainClass =
  23. mainClass.Text.ToString(); 
  24. parameters.IncludeDebugInformation = 
  25. includeDebug.Checked; 
  26. // Add available assemblies - this 
  27. should be enough for the simplest 
  28. // applications. 
  29. foreach (Assembly asm in AppDomain.
  30. CurrentDomain.GetAssemblies()) 
  31. parameters.ReferencedAssemblies.
  32. Add(asm.Location); 
  33. String code = textBox1.Text.ToString(); 
  34. //System.Windows.Forms.MessageBox.
  35. Show(this, code); 
  36. CompilerResults results = 
  37. compiler.CompileAssemblyFromSource
  38. (parameters, code); 
  39. if (results.Errors.Count > 0) 
  40. string errors = "Compilation failed:\n"; 
  41. foreach (CompilerError err 
  42. in results.Errors) 
  43. errors += err.ToString() + "\n"; 
  44. System.Windows.Forms.MessageBox.
  45. Show(this, errors, 
  46. "There were compilation errors"); 
  47. else 
  48. #region Executing generated executable 
  49. // try to execute application 
  50. try 
  51. if (!System.IO.File.Exists(appName.
  52. Text.ToString())) 
  53. MessageBox.Show(String.Format("Can't 
  54. find {0}", appName), 
  55. "Can't execute.", MessageBoxButtons.OK, 
  56. MessageBoxIcon.Error); 
  57. return; 
  58. ProcessStartInfo pInfo = 
  59. new ProcessStartInfo(appName.Text.ToString()); 
  60. Process.Start(pInfo); 
  61. } it55.com 
  62. catch (Exception ex) 
  63. MessageBox.Show(String.Format(
  64. "Error while executing {0}", 
  65. appName) + ex.ToString(), 
  66. "Can't execute.", 
  67. MessageBoxButtons.OK, 
  68. MessageBoxIcon.Error); 
  69. #endregion 

網(wǎng)站標(biāo)題:如何在Win界面上完成C#編譯
網(wǎng)站網(wǎng)址:http://www.5511xx.com/article/djipssi.html