InitVsaEngine() private method

private InitVsaEngine ( string rootMoniker, IVsaSite site ) : void
rootMoniker string
site IVsaSite
return void
Exemplo n.º 1
0
        // Make a new engine instance and set it up for stand-alone operation.
        internal static VsaEngine MakeNewEngine()
        {
            VsaEngine engine = new VsaEngine(true);

            engine.InitVsaEngine
                ("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
                new ThrowOnErrorVsaSite());
            return(engine);
        }
Exemplo n.º 2
0
        public static GlobalScope CreateEngineAndGetGlobalScope(bool fast, string [] assembly_names)
        {
            int         i, n;
            GlobalScope scope;

            VsaEngine engine = new VsaEngine(fast);

            engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
                                 new DefaultVsaSite());
            n = assembly_names.Length;

            for (i = 0; i < n; i++)
            {
                string           assembly_name = assembly_names [i];
                VsaReferenceItem r             = (VsaReferenceItem)engine.Items.CreateItem(assembly_name,
                                                                                           VsaItemType.Reference,
                                                                                           VsaItemFlag.None);
                r.AssemblyName = assembly_name;
            }
            scope = (GlobalScope)engine.GetGlobalScope().GetObject();
            return(scope);
        }
Exemplo n.º 3
0
      // This factory method is called by DLL code only
      public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle){
        Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
        Assembly callingAssembly = callingType.Assembly;
        Object o = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + callingAssembly.FullName);
        if (o != null){
          VsaEngine e = o as VsaEngine;
          if (e != null)
            return e;
        }

        VsaEngine engine = new VsaEngine(callingAssembly);
        engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());

        GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
        scope.globalObject = engine.Globals.globalObject;

        // for every global class generated in this assembly make an instance and call the global code method
        int i = 0;
        Type globalClassType = null;
        do{
          String globalClassName = "JScript " + i.ToString();
          globalClassType = callingAssembly.GetType(globalClassName, false);
          if (globalClassType != null){
            engine.SetEnclosingContext(new WrappedNamespace("", engine));
            ConstructorInfo globalScopeConstructor = globalClassType.GetConstructor(new Type[]{typeof(GlobalScope)});
            MethodInfo globalCode = globalClassType.GetMethod("Global Code");
            Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
            globalCode.Invoke(globalClassInstance, new Object[0]);
          }
          i++;
        }while (globalClassType != null);

        if (o == null)
          System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
        return engine;
      }
Exemplo n.º 4
0
 internal static VsaEngine CreateEngineForDebugger(){
   VsaEngine engine = new VsaEngine(true);
   engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
   GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
   scope.globalObject = engine.Globals.globalObject;
   return engine;
 }
Exemplo n.º 5
0
      private static volatile VsaEngine exeEngine;    // Instance of VsaEngine used by JScript EXEs

      // This factory method is called by EXE code only
      public static VsaEngine CreateEngine(){
        if (VsaEngine.exeEngine == null){
          VsaEngine e = new VsaEngine(true);
          e.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
          VsaEngine.exeEngine = e;
        }
        return VsaEngine.exeEngine;
      }
Exemplo n.º 6
0
 public static GlobalScope CreateEngineAndGetGlobalScopeWithType(bool fast, String[] assemblyNames, RuntimeTypeHandle callingTypeHandle){
   VsaEngine engine = new VsaEngine(fast);
   engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
   engine.doPrint = true;
   engine.SetEnclosingContext(new WrappedNamespace("", engine));
   foreach (String assemblyName in assemblyNames){
     VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
     r.AssemblyName = assemblyName;
   }
   // Put the engine in the CallContext so that calls to CreateEngineWithType will return this engine
   Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
   Assembly callingAssembly = callingType.Assembly;
   System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
   // Get and return the global scope
   GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
   scope.globalObject = engine.Globals.globalObject;
   return scope;
 }
Exemplo n.º 7
0
 public static GlobalScope CreateEngineAndGetGlobalScope(bool fast, String[] assemblyNames){
   VsaEngine engine = new VsaEngine(fast);
   engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
   engine.doPrint = true;
   engine.SetEnclosingContext(new WrappedNamespace("", engine));
   foreach (String assemblyName in assemblyNames){
     VsaReference r = (VsaReference)engine.vsaItems.CreateItem(assemblyName, VsaItemType.Reference, VsaItemFlag.None);
     r.AssemblyName = assemblyName;
   }
   VsaEngine.exeEngine = engine;
   GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
   scope.globalObject = engine.Globals.globalObject;
   return scope;
 }
Exemplo n.º 8
0
Arquivo: mjs.cs Projeto: nobled/mono
		//
		// 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 ();
		}
Exemplo n.º 9
0
    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.LCID;
        engine.GenerateDebugInfo = options.fDebug;

        engine.SetOption("AutoRef", options.autoRef);
        engine.SetOption("fast", options.fFast);
        engine.SetOption("output", options.strOutputFileName);
        engine.SetOption("PEFileKind", options.PEFileKind);
        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)
        {
            this.AddAssemblyReference(engine, assemblyName);
            string filename = Path.GetFileName(assemblyName);
            if (String.Compare(filename, "mscorlib.dll", true, CultureInfo.InvariantCulture) == 0)
            {
                fStdlibAdded = true;
            }
            else if (String.Compare(filename, "System.Windows.Forms.dll", true, CultureInfo.InvariantCulture) == 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, options.fForceCodepage);
        }

        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);
        }
        return(isCompiled);
    }
Exemplo n.º 10
0
 public static Object JScriptExceptionValue(Object e, VsaEngine engine){
   if (engine == null){
     engine = new VsaEngine(true);
     engine.InitVsaEngine("JS7://Microsoft.JScript.Vsa.VsaEngine", new DefaultVsaSite());
   }
   ErrorConstructor originalError = engine.Globals.globalObject.originalError;
   if (e is JScriptException){
     Object value = ((JScriptException)e).value;
     if (value is Exception || value is Missing || (((JScriptException)e).Number&0xFFFF) != (int)JSError.UncaughtException)
       return originalError.Construct((Exception)e);
     return value; //The exception wraps a non-exception value
   }else if (e is StackOverflowException)
     return originalError.Construct(new JScriptException(JSError.OutOfStack));
   else if (e is OutOfMemoryException)
     return originalError.Construct(new JScriptException(JSError.OutOfMemory));
   return originalError.Construct(e);
 }
Exemplo n.º 11
0
		public static GlobalScope CreateEngineAndGetGlobalScope (bool fast, string [] assembly_names)
		{
			int i, n;
			GlobalScope scope;

			VsaEngine engine = new VsaEngine (fast);			
			engine.InitVsaEngine ("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
					      new DefaultVsaSite ());
			n = assembly_names.Length;

			for (i = 0; i < n; i++) {
				string assembly_name = assembly_names [i];
				VsaReferenceItem r = (VsaReferenceItem) engine.Items.CreateItem (assembly_name,
												 VsaItemType.Reference,
												 VsaItemFlag.None);
				r.AssemblyName = assembly_name;
			}
			scope = (GlobalScope) engine.GetGlobalScope ().GetObject ();
			return scope;
		}
Exemplo n.º 12
0
	// Make a new engine instance and set it up for stand-alone operation.
	internal static VsaEngine MakeNewEngine()
			{
				VsaEngine engine = new VsaEngine(true);
				engine.InitVsaEngine
					("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
					 new ThrowOnErrorVsaSite());
				return engine;
			}
 public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle)
 {
     Assembly runtimeAssembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
     object data = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + runtimeAssembly.FullName);
     if (data != null)
     {
         VsaEngine engine = data as VsaEngine;
         if (engine != null)
         {
             return engine;
         }
     }
     VsaEngine engine2 = new VsaEngine(runtimeAssembly);
     engine2.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
     GlobalScope scope = (GlobalScope) engine2.GetGlobalScope().GetObject();
     scope.globalObject = engine2.Globals.globalObject;
     int num = 0;
     Type type = null;
     do
     {
         string name = "JScript " + num.ToString(CultureInfo.InvariantCulture);
         type = runtimeAssembly.GetType(name, false);
         if (type != null)
         {
             engine2.SetEnclosingContext(new WrappedNamespace("", engine2));
             ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(GlobalScope) });
             MethodInfo method = type.GetMethod("Global Code");
             try
             {
                 object obj3 = constructor.Invoke(new object[] { scope });
                 method.Invoke(obj3, new object[0]);
             }
             catch (SecurityException)
             {
                 break;
             }
         }
         num++;
     }
     while (type != null);
     if (data == null)
     {
         System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + runtimeAssembly.FullName, engine2);
     }
     return engine2;
 }
 public static GlobalScope CreateEngineAndGetGlobalScopeWithTypeAndRootNamespace(bool fast, string[] assemblyNames, RuntimeTypeHandle callingTypeHandle, string rootNamespace)
 {
     VsaEngine engine = new VsaEngine(fast);
     engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());
     engine.doPrint = true;
     engine.SetEnclosingContext(new WrappedNamespace("", engine));
     if (rootNamespace != null)
     {
         engine.SetEnclosingContext(new WrappedNamespace(rootNamespace, engine));
     }
     foreach (string str in assemblyNames)
     {
         VsaReference reference = (VsaReference) engine.vsaItems.CreateItem(str, JSVsaItemType.Reference, JSVsaItemFlag.None);
         reference.AssemblyName = str;
     }
     Assembly assembly = Type.GetTypeFromHandle(callingTypeHandle).Assembly;
     System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + assembly.FullName, engine);
     GlobalScope scope = (GlobalScope) engine.GetGlobalScope().GetObject();
     scope.globalObject = engine.Globals.globalObject;
     return scope;
 }
      private VsaEngine CreateAndInitEngine(CompilerParameters options, string[] sourceFiles, string outputFile, TextWriter output){
        VsaEngine engine = new VsaEngine(true);
        VsaSite site = new VsaSite(output);
        engine.InitVsaEngine("JSCodeGenerator://Microsoft.JScript.Vsa.VsaEngine", site);

        // Ensure that all options are valid; throw a CmdLineException otherwise
        this.ValidateOptions(options, engine);

        // Set options on the engine (equivalent of cmdline args in out-of-proc scenario)
        engine.GenerateDebugInfo = options.IncludeDebugInformation;
        engine.SetOption("referenceLoaderAPI", "LoadFile");
        engine.SetOption("fast", true);
        engine.SetOption("print", false);
        engine.SetOption("VersionSafe", false);
        engine.SetOption("output", options.OutputAssembly);
        if (options.GenerateExecutable)
          engine.SetOption("PEFileKind", PEFileKinds.ConsoleApplication);
        else
          engine.SetOption("PEFileKind", PEFileKinds.Dll);
        site.treatWarningsAsErrors = options.TreatWarningsAsErrors;
        engine.SetOption("warnaserror", options.TreatWarningsAsErrors);
        site.warningLevel = options.WarningLevel;
        engine.SetOption("WarningLevel", options.WarningLevel);
        bool stdLibAdded = false;
        foreach (string assemblyName in options.ReferencedAssemblies){
          if (String.Compare(Path.GetFileName(assemblyName), "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
            stdLibAdded = true;
          this.AddAssemblyReference(engine, assemblyName);
        }
        if (!stdLibAdded)
          this.AddAssemblyReference(engine, "mscorlib.dll");

        // Parse any additional compiler options
        StringCollection compilerOptions = this.SplitCmdLineArguments(options.CompilerOptions);
        this.ParseCompilerOptions(engine, compilerOptions, output, options.GenerateExecutable);

        // Add the source files to the engine (as IVsaCodeItems)
        for (int j = 0; j < sourceFiles.Length; j++)
          this.AddSourceFile(engine, sourceFiles[j]);

        return engine;
      }
Exemplo n.º 16
0
      // This factory method is called by DLL code only
      public static VsaEngine CreateEngineWithType(RuntimeTypeHandle callingTypeHandle){
        Type callingType = Type.GetTypeFromHandle(callingTypeHandle);
        Assembly callingAssembly = callingType.Assembly;
        Object o = System.Runtime.Remoting.Messaging.CallContext.GetData("JScript:" + callingAssembly.FullName);
        if (o != null){
          VsaEngine e = o as VsaEngine;
          if (e != null)
            return e;
        }

        VsaEngine engine = new VsaEngine(callingAssembly);
        engine.InitVsaEngine("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa", new DefaultVsaSite());

        GlobalScope scope = (GlobalScope)engine.GetGlobalScope().GetObject();
        scope.globalObject = engine.Globals.globalObject;

        // for every global class generated in this assembly make an instance and call the global code method
        int i = 0;
        Type globalClassType = null;
        do{
          String globalClassName = "JScript " + i.ToString(CultureInfo.InvariantCulture);
          globalClassType = callingAssembly.GetType(globalClassName, false);
          if (globalClassType != null){
            engine.SetEnclosingContext(new WrappedNamespace("", engine));
            ConstructorInfo globalScopeConstructor = globalClassType.GetConstructor(new Type[]{typeof(GlobalScope)});
            MethodInfo globalCode = globalClassType.GetMethod("Global Code");
            try{
              Object globalClassInstance = globalScopeConstructor.Invoke(new Object[]{scope});
              globalCode.Invoke(globalClassInstance, new Object[0]);
            }catch(SecurityException){
              // [stesty] Due to bug 337909, if a JScript assembly is strongly-named but partially-trusted, it will
              //          not succeed here unless it also has the AllowPartiallyTrustedCallersAttribute.  We do not
              //          want to run this constructor with elevated permissions, so we work around by abandoning
              //          the attempt, thus disabling eval in this scenario.
              break;
            }
          }
          i++;
        }while (globalClassType != null);

        if (o == null)
          System.Runtime.Remoting.Messaging.CallContext.SetData("JScript:" + callingAssembly.FullName, engine);
        return engine;
      }
 private VsaEngine CreateAndInitEngine(CompilerParameters options, string[] sourceFiles, string outputFile, TextWriter output)
 {
     VsaEngine engine = new VsaEngine(true);
     VsaSite site = new VsaSite(output);
     engine.InitVsaEngine("JSCodeGenerator://Microsoft.JScript.Vsa.VsaEngine", site);
     this.ValidateOptions(options, engine);
     engine.GenerateDebugInfo = options.IncludeDebugInformation;
     engine.SetOption("referenceLoaderAPI", "LoadFile");
     engine.SetOption("fast", true);
     engine.SetOption("print", false);
     engine.SetOption("VersionSafe", false);
     engine.SetOption("output", options.OutputAssembly);
     if (options.GenerateExecutable)
     {
         engine.SetOption("PEFileKind", PEFileKinds.ConsoleApplication);
     }
     else
     {
         engine.SetOption("PEFileKind", PEFileKinds.Dll);
     }
     site.treatWarningsAsErrors = options.TreatWarningsAsErrors;
     engine.SetOption("warnaserror", options.TreatWarningsAsErrors);
     site.warningLevel = options.WarningLevel;
     engine.SetOption("WarningLevel", options.WarningLevel);
     if ((options.Win32Resource != null) && (options.Win32Resource.Length > 0))
     {
         engine.SetOption("win32resource", options.Win32Resource);
     }
     bool flag = false;
     foreach (string str in options.ReferencedAssemblies)
     {
         if (string.Compare(Path.GetFileName(str), "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0)
         {
             flag = true;
         }
         this.AddAssemblyReference(engine, str);
     }
     if (!flag)
     {
         this.AddAssemblyReference(engine, "mscorlib.dll");
     }
     StringCollection args = this.SplitCmdLineArguments(options.CompilerOptions);
     this.ParseCompilerOptions(engine, args, output, options.GenerateExecutable);
     for (int i = 0; i < sourceFiles.Length; i++)
     {
         this.AddSourceFile(engine, sourceFiles[i]);
     }
     return engine;
 }
Exemplo n.º 18
0
  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;
  }