本文整理汇总了C#中Microsoft.JScript.Vsa.VsaEngine.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# VsaEngine.Compile方法的具体用法?C# VsaEngine.Compile怎么用?C# VsaEngine.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.JScript.Vsa.VsaEngine
的用法示例。
在下文中一共展示了VsaEngine.Compile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//
// Entry point
//
private static void Main (string [] args) {
if (args.Length < 1) {
Usage ();
Environment.Exit (0);
}
MainDriver (args);
VsaEngine engine = new VsaEngine ();
engine.InitVsaEngine ("mjs:com.mono-project", new MonoEngineSite ());
foreach (string asm in references) {
IVsaReferenceItem item = (IVsaReferenceItem) engine.Items.CreateItem (asm, VsaItemType.Reference, VsaItemFlag.None);
item.AssemblyName = asm;
}
string asm_name = String.Empty;
foreach (Assembly assembly in assemblies) {
asm_name = assembly.GetName ().FullName;
IVsaReferenceItem item = (IVsaReferenceItem) engine.Items.CreateItem (asm_name, VsaItemType.Reference, VsaItemFlag.None);
item.AssemblyName = asm_name;
}
foreach (string file in files) {
IVsaCodeItem item = (IVsaCodeItem) engine.Items.CreateItem (file, VsaItemType.Code, VsaItemFlag.None);
item.SourceText = GetCodeFromFile (file);
}
engine.SetOption ("debug", want_debugging_support);
engine.SetOption ("link_path", link_paths);
engine.SetOption ("first_source", first_source);
engine.SetOption ("assemblies", assemblies);
engine.SetOption ("out", output_file);
if (warning_level != -1)
engine.SetOption ("WarningLevel", warning_level);
engine.Compile ();
}
示例2: Compile
bool Compile(CompilerOptions options){
if (this.fPrintTargets)
Console.WriteLine(Localize("Compiling", options.strOutputFileName));
VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine();
if (null == engine)
throw new CmdLineException(CmdLineError.CannotCreateEngine, JScriptCompiler.GetCultureInfo());
engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", new EngineSite(options));
engine.LCID = JScriptCompiler.GetCultureInfo().LCID;
engine.GenerateDebugInfo = options.fDebug;
engine.SetOption("ReferenceLoaderAPI", "ReflectionOnlyLoadFrom");
engine.SetOption("AutoRef", options.autoRef);
engine.SetOption("fast", options.fFast);
engine.SetOption("output", options.strOutputFileName);
engine.SetOption("PEFileKind", options.PEFileKind);
engine.SetOption("PortableExecutableKind", options.PEKindFlags);
engine.SetOption("ImageFileMachine", options.PEMachineArchitecture);
engine.SetOption("print", options.fPrint);
engine.SetOption("libpath", options.libpath);
if (options.versionInfo != null)
engine.SetOption("version", options.versionInfo);
engine.SetOption("VersionSafe", options.fVersionSafe);
engine.SetOption("defines", options.Defines);
engine.SetOption("warnaserror", options.fTreatWarningsAsErrors);
engine.SetOption("WarningLevel", options.nWarningLevel);
if (options.ManagedResources.Count > 0)
engine.SetOption("managedResources", options.ManagedResources.Values);
bool fStdlibAdded = false;
bool fWinFormsAdded = false;
foreach (string assemblyName in options.ImportFileNames){
AddAssemblyReference(engine, assemblyName);
string filename = Path.GetFileName(assemblyName);
if (String.Compare(filename, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
fStdlibAdded = true;
else if (String.Compare(filename, "System.Windows.Forms.dll", StringComparison.OrdinalIgnoreCase) == 0)
fWinFormsAdded = true;
}
// Only add mscorlib if it hasn't already been added.
if (!options.fNoStdlib && !fStdlibAdded)
AddAssemblyReference(engine, "mscorlib.dll");
// add System.Windows.Forms if target is winexe and it hasn't already been added
if ((options.PEFileKind == PEFileKinds.WindowApplication) && !options.fNoStdlib && !fWinFormsAdded)
AddAssemblyReference(engine, "System.Windows.Forms.dll");
for (int j = 0; j < options.SourceFileNames.Count; j++)
AddSourceFile(engine, (string)options.SourceFileNames[j], options.codepage);
bool isCompiled = false;
try{
isCompiled = engine.Compile();
}catch(VsaException e){
// check for expected errors
if (e.ErrorCode == VsaError.AssemblyExpected){
if (e.InnerException != null && e.InnerException is System.BadImageFormatException){
// the reference was not for an assembly
CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, e.Message, JScriptCompiler.GetCultureInfo());
Console.WriteLine(cmdLineError.Message);
}else if (e.InnerException != null && (e.InnerException is System.IO.FileNotFoundException || e.InnerException is System.IO.FileLoadException)){
// the referenced file not valid
CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, JScriptCompiler.GetCultureInfo());
Console.WriteLine(cmdLineError.Message);
}else{
CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, JScriptCompiler.GetCultureInfo());
Console.WriteLine(cmdLineError.Message);
}
}else if (e.ErrorCode == VsaError.SaveCompiledStateFailed){
CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, JScriptCompiler.GetCultureInfo());
Console.WriteLine(cmdLineError.Message);
}else if (e.ErrorCode == VsaError.AssemblyNameInvalid && e.InnerException != null){
CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidCharacters, e.Message, JScriptCompiler.GetCultureInfo());
Console.WriteLine(cmdLineError.Message);
}else{
Console.WriteLine(Localize("INTERNAL COMPILER ERROR"));
Console.WriteLine(e);
}
return false;
}catch(Exception e){
Console.WriteLine(Localize("INTERNAL COMPILER ERROR"));
Console.WriteLine(e);
return false;
}catch{
Console.WriteLine(Localize("INTERNAL COMPILER ERROR"));
return false;
}
return isCompiled;
}