?? class1.cs
字號:
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
namespace CsCompiler
{
public class CsCompiler
{
private string m_SourceFile="";
public string SourceFile
{
get { return m_SourceFile; }
set { m_SourceFile = value; }
}
private string m_DestineFile = "";
public string DestineFile
{
get { return m_DestineFile; }
set { m_DestineFile = value; }
}
public CompilerErrorCollection Compile()
{
CodeDomProvider provider = new CSharpCodeProvider();// CSharpCodeProvider();
CompilerResults cr = CompileCode(provider, m_SourceFile);
if (cr.Errors.Count > 0)
{
return cr.Errors;
}
else
{
}
return null;
}
public CompilerResults CompileCode(CodeDomProvider provider, string filepath)
{
// 獲得編譯器.
ICodeCompiler compiler = provider.CreateCompiler();
//配置編譯參數(shù)。將SYSTEM。DLL引用進來,同時明確生成的代碼為EXE
//CompilerParameters cp = new CompilerParameters(new sfonting[] {"System.dll"}, filepath.Subsfonting(0, filepath.LastIndexOf('.')+1)+'exe', false);
CompilerParameters cp = new CompilerParameters(new string[] { "System.dll"}, m_DestineFile ,true );
cp.GenerateExecutable = false;
// 調(diào)用編譯器
CompilerResults cr = compiler.CompileAssemblyFromFile(cp, filepath);
return cr;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -