A continuación dejo el código:
using System;
using System.Text;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using Microsoft.Win32;
using System.IO;
using System.CodeDom;
public partial class CompactAssembly
{
public static void CreateTestDll()
{
StringBuilder sb = new StringBuilder("");
sb.Append("namespace CSCodeEvaler{ \n");
sb.Append("public class CSCodeEvaler{ \n");
sb.Append("public object EvalCode(){\n");
sb.Append("return 1; \n");
sb.Append("} \n");
sb.Append("} \n");
sb.Append("}\n");
CompactAssembly.CompileCompactAssembly(sb.ToString(), "CodeDomGenerated.dll");
}
public static bool CompileCompactAssembly(string codeToCompile, string outAssemblyName)
{
CodeDomProvider csp = new Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.OutputAssembly = outAssemblyName;
cp.GenerateExecutable = false;
cp.GenerateInMemory = false;
cp.CompilerOptions = @"/noconfig /nostdlib";
cp.ReferencedAssemblies.Add(Path.Combine(@"C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE", "mscorlib.dll"));
CompilerResults cr = csp.CompileAssemblyFromSource(cp, codeToCompile);
return cr.Errors.Count == 0;
}
}
No hay comentarios.:
Publicar un comentario