资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么在Win界面上完成C#编译

这篇文章主要介绍“怎么在Win界面上完成C#编译”,在日常操作中,相信很多人在怎么在Win界面上完成C#编译问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么在Win界面上完成C#编译”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联建站拥有十载的建站服务经验,在此期间,我们发现较多的客户在挑选建站服务商前都非常的犹豫。主要问题集中:在无法预知自己的网站呈现的效果是什么样的?也无法判断选择的服务商设计出来的网页效果自己是否会满意?创新互联建站业务涵盖了互联网平台网站建设、移动平台网站制作、网络推广、定制网站设计等服务。创新互联建站网站开发公司本着不拘一格的网站视觉设计和网站开发技术相结合,为企业做网站提供成熟的网站设计方案。

本文只是可以让大家摆脱csc的约束,在Win界面上完成C#编译编译.

在C#编译过程中你必须以下面的步骤完成:

1.建立一个CSharpCodeProvider 实例(如果是使用Visual Basic则使用VBCodeProvider)

2.包含接口ICodeCompiler

3.提供CompilerParameters的参数

4.使用CompileAssemblyFromSource方法编译。

5.运行CompilerResults

6.执行C#编译好的程序

编译的代码可以是写在文本框中的字符串,当然也可以源文件。

private void button1_Click(object   sender, System.EventArgs e)   {   CSharpCodeProvider codeProvider =   new CSharpCodeProvider();   // For Visual Basic Compiler try this :   //Microsoft.VisualBasic.VBCodeProvider    ICodeCompiler compiler =   codeProvider.CreateCompiler();   CompilerParameters parameters =   new CompilerParameters();    parameters.GenerateExecutable = true;   if (appName.Text == "")   {   System.Windows.Forms.MessageBox.Show(this,   "Application name cannot be empty");   return ;   }    parameters.OutputAssembly = appName.  Text.ToString();    if (mainClass.Text.ToString() == "")   {   System.Windows.Forms.MessageBox.Show(this,   "Main Class Name cannot be empty");   return ;   }    parameters.MainClass =  mainClass.Text.ToString();   parameters.IncludeDebugInformation =   includeDebug.Checked;    // Add available assemblies - this   should be enough for the simplest   // applications.   foreach (Assembly asm in AppDomain.  CurrentDomain.GetAssemblies())   {   parameters.ReferencedAssemblies.  Add(asm.Location);   }    String code = textBox1.Text.ToString();   //System.Windows.Forms.MessageBox.  Show(this, code);    CompilerResults results =   compiler.CompileAssemblyFromSource  (parameters, code);    if (results.Errors.Count > 0)   {   string errors = "Compilation failed:\n";   foreach (CompilerError err   in results.Errors)   {   errors += err.ToString() + "\n";   }   System.Windows.Forms.MessageBox.  Show(this, errors,   "There were compilation errors");   }   else   {   #region Executing generated executable   // try to execute application   try   {   if (!System.IO.File.Exists(appName.  Text.ToString()))   {   MessageBox.Show(String.Format("Can't   find {0}", appName),   "Can't execute.", MessageBoxButtons.OK,   MessageBoxIcon.Error);   return;   }   ProcessStartInfo pInfo =   new ProcessStartInfo(appName.Text.ToString());   Process.Start(pInfo);   } it55.com   catch (Exception ex)   {   MessageBox.Show(String.Format(  "Error while executing {0}",   appName) + ex.ToString(),   "Can't execute.",   MessageBoxButtons.OK,   MessageBoxIcon.Error);   }   #endregion   }   }

到此,关于“怎么在Win界面上完成C#编译”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


本文题目:怎么在Win界面上完成C#编译
文章链接:http://cdkjz.cn/article/ghshod.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220