Example #1
0
 protected override HostObjectInitializationStatus InitializeHostObject()
 {
     if (base.HostObject != null)
     {
         using (RCWForCurrentContext <IVbcHostObject> context = new RCWForCurrentContext <IVbcHostObject>(base.HostObject as IVbcHostObject))
         {
             IVbcHostObject rCW = context.RCW;
             if (rCW != null)
             {
                 bool flag = this.InitializeHostCompiler(rCW);
                 if (rCW.IsDesignTime())
                 {
                     return(flag ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.NoActionReturnFailure);
                 }
                 if (!base.HostCompilerSupportsAllParameters || this.UseAlternateCommandLineToolToExecute())
                 {
                     if (!base.CheckAllReferencesExistOnDisk())
                     {
                         return(HostObjectInitializationStatus.NoActionReturnFailure);
                     }
                     base.UsedCommandLineTool = true;
                     return(HostObjectInitializationStatus.UseAlternateToolToExecute);
                 }
                 if (flag)
                 {
                     return(rCW.IsUpToDate() ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.UseHostObjectToExecute);
                 }
                 return(HostObjectInitializationStatus.NoActionReturnFailure);
             }
             base.Log.LogErrorWithCodeFromResources("General.IncorrectHostObject", new object[] { "Vbc", "IVbcHostObject" });
         }
     }
     base.UsedCommandLineTool = true;
     return(HostObjectInitializationStatus.UseAlternateToolToExecute);
 }
Example #2
0
        protected override bool CallHostObjectToExecute()
        {
            bool           flag;
            IVbcHostObject hostObject = base.HostObject as IVbcHostObject;

            try
            {
                CodeMarkers.Instance.CodeMarker(CodeMarkerEvent.perfMSBuildHostCompileBegin);
                flag = hostObject.Compile();
            }
            finally
            {
                CodeMarkers.Instance.CodeMarker(CodeMarkerEvent.perfMSBuildHostCompileEnd);
            }
            return(flag);
        }
Example #3
0
        /// <summary>
        /// This method will initialize the host compiler object with all the switches,
        /// parameters, resources, references, sources, etc.
        ///
        /// It returns true if everything went according to plan.  It returns false if the
        /// host compiler had a problem with one of the parameters that was passed in.
        /// 
        /// This method also sets the "this.HostCompilerSupportsAllParameters" property
        /// accordingly.
        ///
        /// Example:
        ///     If we attempted to pass in Platform="foobar", then this method would
        ///     set HostCompilerSupportsAllParameters=true, but it would throw an 
        ///     exception because the host compiler fully supports
        ///     the Platform parameter, but "foobar" is an illegal value.
        ///
        /// Example:
        ///     If we attempted to pass in NoConfig=false, then this method would set
        ///     HostCompilerSupportsAllParameters=false, because while this is a legal
        ///     thing for csc.exe, the IDE compiler cannot support it.  In this situation
        ///     the return value will also be false.
        /// </summary>
        /// <owner>RGoel</owner>
        private bool InitializeHostCompiler(IVbcHostObject vbcHostObject)
        {
            this.HostCompilerSupportsAllParameters = this.UseHostCompilerIfAvailable;
            string param = "Unknown";

            try
            {
                param = nameof(vbcHostObject.BeginInitialization);
                vbcHostObject.BeginInitialization();

                CheckHostObjectSupport(param = nameof(AdditionalLibPaths), vbcHostObject.SetAdditionalLibPaths(AdditionalLibPaths));
                CheckHostObjectSupport(param = nameof(AddModules), vbcHostObject.SetAddModules(AddModules));

                // For host objects which support them, set the analyzers, ruleset and additional files.
                IAnalyzerHostObject analyzerHostObject = vbcHostObject as IAnalyzerHostObject;
                if (analyzerHostObject != null)
                {
                    CheckHostObjectSupport(param = nameof(Analyzers), analyzerHostObject.SetAnalyzers(Analyzers));
                    CheckHostObjectSupport(param = nameof(CodeAnalysisRuleSet), analyzerHostObject.SetRuleSet(CodeAnalysisRuleSet));
                    CheckHostObjectSupport(param = nameof(AdditionalFiles), analyzerHostObject.SetAdditionalFiles(AdditionalFiles));
                }

                CheckHostObjectSupport(param = nameof(BaseAddress), vbcHostObject.SetBaseAddress(TargetType, GetBaseAddressInHex()));
                CheckHostObjectSupport(param = nameof(CodePage), vbcHostObject.SetCodePage(CodePage));
                CheckHostObjectSupport(param = nameof(DebugType), vbcHostObject.SetDebugType(EmitDebugInformation, DebugType));
                CheckHostObjectSupport(param = nameof(DefineConstants), vbcHostObject.SetDefineConstants(DefineConstants));
                CheckHostObjectSupport(param = nameof(DelaySign), vbcHostObject.SetDelaySign(DelaySign));
                CheckHostObjectSupport(param = nameof(DocumentationFile), vbcHostObject.SetDocumentationFile(DocumentationFile));
                CheckHostObjectSupport(param = nameof(FileAlignment), vbcHostObject.SetFileAlignment(FileAlignment));
                CheckHostObjectSupport(param = nameof(GenerateDocumentation), vbcHostObject.SetGenerateDocumentation(GenerateDocumentation));
                CheckHostObjectSupport(param = nameof(Imports), vbcHostObject.SetImports(Imports));
                CheckHostObjectSupport(param = nameof(KeyContainer), vbcHostObject.SetKeyContainer(KeyContainer));
                CheckHostObjectSupport(param = nameof(KeyFile), vbcHostObject.SetKeyFile(KeyFile));
                CheckHostObjectSupport(param = nameof(LinkResources), vbcHostObject.SetLinkResources(LinkResources));
                CheckHostObjectSupport(param = nameof(MainEntryPoint), vbcHostObject.SetMainEntryPoint(MainEntryPoint));
                CheckHostObjectSupport(param = nameof(NoConfig), vbcHostObject.SetNoConfig(NoConfig));
                CheckHostObjectSupport(param = nameof(NoStandardLib), vbcHostObject.SetNoStandardLib(NoStandardLib));
                CheckHostObjectSupport(param = nameof(NoWarnings), vbcHostObject.SetNoWarnings(NoWarnings));
                CheckHostObjectSupport(param = nameof(Optimize), vbcHostObject.SetOptimize(Optimize));
                CheckHostObjectSupport(param = nameof(OptionCompare), vbcHostObject.SetOptionCompare(OptionCompare));
                CheckHostObjectSupport(param = nameof(OptionExplicit), vbcHostObject.SetOptionExplicit(OptionExplicit));
                CheckHostObjectSupport(param = nameof(OptionStrict), vbcHostObject.SetOptionStrict(OptionStrict));
                CheckHostObjectSupport(param = nameof(OptionStrictType), vbcHostObject.SetOptionStrictType(OptionStrictType));
                CheckHostObjectSupport(param = nameof(OutputAssembly), vbcHostObject.SetOutputAssembly(OutputAssembly?.ItemSpec));

                // For host objects which support them, set platform with 32BitPreference, HighEntropyVA, and SubsystemVersion
                IVbcHostObject5 vbcHostObject5 = vbcHostObject as IVbcHostObject5;
                if (vbcHostObject5 != null)
                {
                    CheckHostObjectSupport(param = nameof(PlatformWith32BitPreference), vbcHostObject5.SetPlatformWith32BitPreference(PlatformWith32BitPreference));
                    CheckHostObjectSupport(param = nameof(HighEntropyVA), vbcHostObject5.SetHighEntropyVA(HighEntropyVA));
                    CheckHostObjectSupport(param = nameof(SubsystemVersion), vbcHostObject5.SetSubsystemVersion(SubsystemVersion));
                }
                else
                {
                    CheckHostObjectSupport(param = nameof(Platform), vbcHostObject.SetPlatform(Platform));
                }

                IVbcHostObject6 vbcHostObject6 = vbcHostObject as IVbcHostObject6;
                if (vbcHostObject6 != null)
                {
                    CheckHostObjectSupport(param = nameof(ErrorLog), vbcHostObject6.SetErrorLog(ErrorLog));
                    CheckHostObjectSupport(param = nameof(ReportAnalyzer), vbcHostObject6.SetReportAnalyzer(ReportAnalyzer));
                }

                CheckHostObjectSupport(param = nameof(References), vbcHostObject.SetReferences(References));
                CheckHostObjectSupport(param = nameof(RemoveIntegerChecks), vbcHostObject.SetRemoveIntegerChecks(RemoveIntegerChecks));
                CheckHostObjectSupport(param = nameof(Resources), vbcHostObject.SetResources(Resources));
                CheckHostObjectSupport(param = nameof(ResponseFiles), vbcHostObject.SetResponseFiles(ResponseFiles));
                CheckHostObjectSupport(param = nameof(RootNamespace), vbcHostObject.SetRootNamespace(RootNamespace));
                CheckHostObjectSupport(param = nameof(SdkPath), vbcHostObject.SetSdkPath(SdkPath));
                CheckHostObjectSupport(param = nameof(Sources), vbcHostObject.SetSources(Sources));
                CheckHostObjectSupport(param = nameof(TargetCompactFramework), vbcHostObject.SetTargetCompactFramework(TargetCompactFramework));
                CheckHostObjectSupport(param = nameof(TargetType), vbcHostObject.SetTargetType(TargetType));
                CheckHostObjectSupport(param = nameof(TreatWarningsAsErrors), vbcHostObject.SetTreatWarningsAsErrors(TreatWarningsAsErrors));
                CheckHostObjectSupport(param = nameof(WarningsAsErrors), vbcHostObject.SetWarningsAsErrors(WarningsAsErrors));
                CheckHostObjectSupport(param = nameof(WarningsNotAsErrors), vbcHostObject.SetWarningsNotAsErrors(WarningsNotAsErrors));
                // DisabledWarnings needs to come after WarningsAsErrors and WarningsNotAsErrors, because
                // of the way the host object works, and the fact that DisabledWarnings trump Warnings[Not]AsErrors.
                CheckHostObjectSupport(param = nameof(DisabledWarnings), vbcHostObject.SetDisabledWarnings(DisabledWarnings));
                CheckHostObjectSupport(param = nameof(Win32Icon), vbcHostObject.SetWin32Icon(Win32Icon));
                CheckHostObjectSupport(param = nameof(Win32Resource), vbcHostObject.SetWin32Resource(Win32Resource));

                // In order to maintain compatibility with previous host compilers, we must
                // light-up for IVbcHostObject2
                if (vbcHostObject is IVbcHostObject2)
                {
                    IVbcHostObject2 vbcHostObject2 = (IVbcHostObject2)vbcHostObject;
                    CheckHostObjectSupport(param = nameof(ModuleAssemblyName), vbcHostObject2.SetModuleAssemblyName(ModuleAssemblyName));
                    CheckHostObjectSupport(param = nameof(OptionInfer), vbcHostObject2.SetOptionInfer(OptionInfer));
                    CheckHostObjectSupport(param = nameof(Win32Manifest), vbcHostObject2.SetWin32Manifest(GetWin32ManifestSwitch(NoWin32Manifest, Win32Manifest)));
                    // initialize option Infer
                    CheckHostObjectSupport(param = nameof(OptionInfer), vbcHostObject2.SetOptionInfer(OptionInfer));
                }
                else
                {
                    // If we have been given a property that the host compiler doesn't support
                    // then we need to state that we are falling back to the command line compiler
                    if (!String.IsNullOrEmpty(ModuleAssemblyName))
                    {
                        CheckHostObjectSupport(param = nameof(ModuleAssemblyName), resultFromHostObjectSetOperation: false);
                    }

                    if (_store.ContainsKey(nameof(OptionInfer)))
                    {
                        CheckHostObjectSupport(param = nameof(OptionInfer), resultFromHostObjectSetOperation: false);
                    }

                    if (!String.IsNullOrEmpty(Win32Manifest))
                    {
                        CheckHostObjectSupport(param = nameof(Win32Manifest), resultFromHostObjectSetOperation: false);
                    }
                }

                // Check for support of the LangVersion property
                if (vbcHostObject is IVbcHostObject3)
                {
                    IVbcHostObject3 vbcHostObject3 = (IVbcHostObject3)vbcHostObject;
                    CheckHostObjectSupport(param = nameof(LangVersion), vbcHostObject3.SetLanguageVersion(LangVersion));
                }
                else if (!String.IsNullOrEmpty(LangVersion) && !UsedCommandLineTool)
                {
                    CheckHostObjectSupport(param = nameof(LangVersion), resultFromHostObjectSetOperation: false);
                }

                if (vbcHostObject is IVbcHostObject4)
                {
                    IVbcHostObject4 vbcHostObject4 = (IVbcHostObject4)vbcHostObject;
                    CheckHostObjectSupport(param = nameof(VBRuntime), vbcHostObject4.SetVBRuntime(VBRuntime));
                }
                // Support for NoVBRuntimeReference was added to this task after IVbcHostObject was frozen. That doesn't matter much because the host
                // compiler doesn't support it, and almost nobody uses it anyway. But if someone has set it, we need to hard code falling back to
                // the command line compiler here.
                if (NoVBRuntimeReference)
                {
                    CheckHostObjectSupport(param = nameof(NoVBRuntimeReference), resultFromHostObjectSetOperation: false);
                }

                // In general, we don't support preferreduilang with the in-proc compiler.  It will always use the same locale as the
                // host process, so in general, we have to fall back to the command line compiler if this option is specified.
                // However, we explicitly allow two values (mostly for parity with C#):
                // Null is supported because it means that option should be omitted, and compiler default used - obviously always valid.
                // Explicitly specified name of current locale is also supported, since it is effectively a no-op.
                if (!String.IsNullOrEmpty(PreferredUILang) && !String.Equals(PreferredUILang, System.Globalization.CultureInfo.CurrentUICulture.Name, StringComparison.OrdinalIgnoreCase))
                {
                    CheckHostObjectSupport(param = nameof(PreferredUILang), resultFromHostObjectSetOperation: false);
                }
            }
            catch (Exception e)
            {
                if (this.HostCompilerSupportsAllParameters)
                {
                    // If the host compiler doesn't support everything we need, we're going to end up 
                    // shelling out to the command-line compiler anyway.  That means the command-line
                    // compiler will log the error.  So here, we only log the error if we would've
                    // tried to use the host compiler.
                    Log.LogErrorWithCodeFromResources("General_CouldNotSetHostObjectParameter", param, e.Message);
                }

                return false;
            }
            finally
            {
                // In the case of the VB host compiler, the EndInitialization method will
                // throw (due to FAILED HRESULT) if there was a bad value for one of the
                // parameters.
                vbcHostObject.EndInitialization();
            }

            return true;
        }
Example #4
0
        /// <summary>
        /// This method will initialize the host compiler object with all the switches,
        /// parameters, resources, references, sources, etc.
        ///
        /// It returns true if everything went according to plan.  It returns false if the
        /// host compiler had a problem with one of the parameters that was passed in.
        /// 
        /// This method also sets the "this.HostCompilerSupportsAllParameters" property
        /// accordingly.
        ///
        /// Example:
        ///     If we attempted to pass in Platform="foo", then this method would
        ///     set HostCompilerSupportsAllParameters=true, but it would throw an 
        ///     exception because the host compiler fully supports
        ///     the Platform parameter, but "foo" is an illegal value.
        ///
        /// Example:
        ///     If we attempted to pass in NoConfig=false, then this method would set
        ///     HostCompilerSupportsAllParameters=false, because while this is a legal
        ///     thing for csc.exe, the IDE compiler cannot support it.  In this situation
        ///     the return value will also be false.
        /// </summary>
        private bool InitializeHostCompiler
            (
            // NOTE: For compat reasons this must remain IVbcHostObject
            // we can dynamically test for smarter interfaces later..
            IVbcHostObject vbcHostObject
            )
        {
            this.HostCompilerSupportsAllParameters = this.UseHostCompilerIfAvailable;
            string param = "Unknown";

            try
            {
                param = "BeginInitialization";
                vbcHostObject.BeginInitialization();

                param = "AdditionalLibPaths"; this.CheckHostObjectSupport(param, vbcHostObject.SetAdditionalLibPaths(this.AdditionalLibPaths));
                param = "AddModules"; this.CheckHostObjectSupport(param, vbcHostObject.SetAddModules(this.AddModules));

                // For host objects which support them, set the analyzers, ruleset and additional files.
                IAnalyzerHostObject analyzerHostObject = vbcHostObject as IAnalyzerHostObject;
                if (analyzerHostObject != null)
                {
                    param = "Analyzers"; this.CheckHostObjectSupport(param, analyzerHostObject.SetAnalyzers(this.Analyzers));
                    param = "CodeAnalysisRuleSet"; this.CheckHostObjectSupport(param, analyzerHostObject.SetRuleSet(this.CodeAnalysisRuleSet));
                    param = "AdditionalFiles"; this.CheckHostObjectSupport(param, analyzerHostObject.SetAdditionalFiles(this.AdditionalFiles));
                }

                param = "BaseAddress"; this.CheckHostObjectSupport(param, vbcHostObject.SetBaseAddress(this.TargetType, this.GetBaseAddressInHex()));
                param = "CodePage"; this.CheckHostObjectSupport(param, vbcHostObject.SetCodePage(this.CodePage));
                param = "DebugType"; this.CheckHostObjectSupport(param, vbcHostObject.SetDebugType(this.EmitDebugInformation, this.DebugType));
                param = "DefineConstants"; this.CheckHostObjectSupport(param, vbcHostObject.SetDefineConstants(this.DefineConstants));
                param = "DelaySign"; this.CheckHostObjectSupport(param, vbcHostObject.SetDelaySign(this.DelaySign));
                param = "DocumentationFile"; this.CheckHostObjectSupport(param, vbcHostObject.SetDocumentationFile(this.DocumentationFile));
                param = "FileAlignment"; this.CheckHostObjectSupport(param, vbcHostObject.SetFileAlignment(this.FileAlignment));
                param = "GenerateDocumentation"; this.CheckHostObjectSupport(param, vbcHostObject.SetGenerateDocumentation(this.GenerateDocumentation));
                param = "Imports"; this.CheckHostObjectSupport(param, vbcHostObject.SetImports(this.Imports));
                param = "KeyContainer"; this.CheckHostObjectSupport(param, vbcHostObject.SetKeyContainer(this.KeyContainer));
                param = "KeyFile"; this.CheckHostObjectSupport(param, vbcHostObject.SetKeyFile(this.KeyFile));
                param = "LinkResources"; this.CheckHostObjectSupport(param, vbcHostObject.SetLinkResources(this.LinkResources));
                param = "MainEntryPoint"; this.CheckHostObjectSupport(param, vbcHostObject.SetMainEntryPoint(this.MainEntryPoint));
                param = "NoConfig"; this.CheckHostObjectSupport(param, vbcHostObject.SetNoConfig(this.NoConfig));
                param = "NoStandardLib"; this.CheckHostObjectSupport(param, vbcHostObject.SetNoStandardLib(this.NoStandardLib));
                param = "NoWarnings"; this.CheckHostObjectSupport(param, vbcHostObject.SetNoWarnings(this.NoWarnings));
                param = "Optimize"; this.CheckHostObjectSupport(param, vbcHostObject.SetOptimize(this.Optimize));
                param = "OptionCompare"; this.CheckHostObjectSupport(param, vbcHostObject.SetOptionCompare(this.OptionCompare));
                param = "OptionExplicit"; this.CheckHostObjectSupport(param, vbcHostObject.SetOptionExplicit(this.OptionExplicit));
                param = "OptionStrict"; this.CheckHostObjectSupport(param, vbcHostObject.SetOptionStrict(this.OptionStrict));
                param = "OptionStrictType"; this.CheckHostObjectSupport(param, vbcHostObject.SetOptionStrictType(this.OptionStrictType));
                param = "OutputAssembly"; this.CheckHostObjectSupport(param, vbcHostObject.SetOutputAssembly(this.OutputAssembly.ItemSpec));

                // For host objects which support them, set platform with 32BitPreference, HighEntropyVA, and SubsystemVersion
                IVbcHostObject5 vbcHostObject5 = vbcHostObject as IVbcHostObject5;
                if (vbcHostObject5 != null)
                {
                    param = "PlatformWith32BitPreference"; this.CheckHostObjectSupport(param, vbcHostObject5.SetPlatformWith32BitPreference(this.PlatformWith32BitPreference));
                    param = "HighEntropyVA"; this.CheckHostObjectSupport(param, vbcHostObject5.SetHighEntropyVA(this.HighEntropyVA));
                    param = "SubsystemVersion"; this.CheckHostObjectSupport(param, vbcHostObject5.SetSubsystemVersion(this.SubsystemVersion));
                }
                else
                {
                    param = "Platform"; this.CheckHostObjectSupport(param, vbcHostObject.SetPlatform(this.Platform));
                }

                param = "References"; this.CheckHostObjectSupport(param, vbcHostObject.SetReferences(this.References));
                param = "RemoveIntegerChecks"; this.CheckHostObjectSupport(param, vbcHostObject.SetRemoveIntegerChecks(this.RemoveIntegerChecks));
                param = "Resources"; this.CheckHostObjectSupport(param, vbcHostObject.SetResources(this.Resources));
                param = "ResponseFiles"; this.CheckHostObjectSupport(param, vbcHostObject.SetResponseFiles(this.ResponseFiles));
                param = "RootNamespace"; this.CheckHostObjectSupport(param, vbcHostObject.SetRootNamespace(this.RootNamespace));
                param = "SdkPath"; this.CheckHostObjectSupport(param, vbcHostObject.SetSdkPath(this.SdkPath));
                param = "Sources"; this.CheckHostObjectSupport(param, vbcHostObject.SetSources(this.Sources));
                param = "TargetCompactFramework"; this.CheckHostObjectSupport(param, vbcHostObject.SetTargetCompactFramework(this.TargetCompactFramework));
                param = "TargetType"; this.CheckHostObjectSupport(param, vbcHostObject.SetTargetType(this.TargetType));
                param = "TreatWarningsAsErrors"; this.CheckHostObjectSupport(param, vbcHostObject.SetTreatWarningsAsErrors(this.TreatWarningsAsErrors));
                param = "WarningsAsErrors"; this.CheckHostObjectSupport(param, vbcHostObject.SetWarningsAsErrors(this.WarningsAsErrors));
                param = "WarningsNotAsErrors"; this.CheckHostObjectSupport(param, vbcHostObject.SetWarningsNotAsErrors(this.WarningsNotAsErrors));
                // DisabledWarnings needs to come after WarningsAsErrors and WarningsNotAsErrors, because
                // of the way the host object works, and the fact that DisabledWarnings trump Warnings[Not]AsErrors.
                param = "DisabledWarnings"; this.CheckHostObjectSupport(param, vbcHostObject.SetDisabledWarnings(this.DisabledWarnings));
                param = "Win32Icon"; this.CheckHostObjectSupport(param, vbcHostObject.SetWin32Icon(this.Win32Icon));
                param = "Win32Resource"; this.CheckHostObjectSupport(param, vbcHostObject.SetWin32Resource(this.Win32Resource));

                // In order to maintain compatibility with previous host compilers, we must
                // light-up for IVbcHostObject2
                if (vbcHostObject is IVbcHostObject2)
                {
                    IVbcHostObject2 vbcHostObject2 = (IVbcHostObject2)vbcHostObject;
                    param = "ModuleAssemblyName"; this.CheckHostObjectSupport(param, vbcHostObject2.SetModuleAssemblyName(this.ModuleAssemblyName));
                    param = "OptionInfer"; this.CheckHostObjectSupport(param, vbcHostObject2.SetOptionInfer(this.OptionInfer));
                    param = "Win32Manifest"; this.CheckHostObjectSupport(param, vbcHostObject2.SetWin32Manifest(this.GetWin32ManifestSwitch(this.NoWin32Manifest, this.Win32Manifest)));
                    // initialize option Infer
                    CheckHostObjectSupport("OptionInfer", vbcHostObject2.SetOptionInfer(this.OptionInfer));
                }
                else
                {
                    // If we have been given a property that the host compiler doesn't support
                    // then we need to state that we are falling back to the command line compiler
                    if (!String.IsNullOrEmpty(ModuleAssemblyName))
                    {
                        CheckHostObjectSupport("ModuleAssemblyName", false);
                    }

                    if (Bag.ContainsKey("OptionInfer"))
                    {
                        CheckHostObjectSupport("OptionInfer", false);
                    }

                    if (!String.IsNullOrEmpty(Win32Manifest))
                    {
                        CheckHostObjectSupport("Win32Manifest", false);
                    }
                }

                // Check for support of the LangVersion property
                if (vbcHostObject is IVbcHostObject3)
                {
                    IVbcHostObject3 vbcHostObject3 = (IVbcHostObject3)vbcHostObject;
                    param = "LangVersion"; this.CheckHostObjectSupport(param, vbcHostObject3.SetLanguageVersion(this.LangVersion));
                }
                else if (!String.IsNullOrEmpty(this.LangVersion) && !this.UsedCommandLineTool)
                {
                    CheckHostObjectSupport("LangVersion", false);
                }

                if (vbcHostObject is IVbcHostObject4)
                {
                    IVbcHostObject4 vbcHostObject4 = (IVbcHostObject4)vbcHostObject;
                    param = "VBRuntime"; this.CheckHostObjectSupport(param, vbcHostObject4.SetVBRuntime(this.VBRuntime));
                }
                // Support for NoVBRuntimeReference was added to this task after IVbcHostObject was frozen. That doesn't matter much because the host
                // compiler doesn't support it, and almost nobody uses it anyway. But if someone has set it, we need to hard code falling back to
                // the command line compiler here.
                if (NoVBRuntimeReference)
                {
                    CheckHostObjectSupport("NoVBRuntimeReference", false);
                }

                // In general, we don't support preferreduilang with the in-proc compiler.  It will always use the same locale as the
                // host process, so in general, we have to fall back to the command line compiler if this option is specified.
                // However, we explicitly allow two values (mostly for parity with C#):
                // Null is supported because it means that option should be omitted, and compiler default used - obviously always valid.
                // Explicitly specified name of current locale is also supported, since it is effectively a no-op.
                if (!String.IsNullOrEmpty(PreferredUILang) && !String.Equals(PreferredUILang, System.Globalization.CultureInfo.CurrentUICulture.Name, StringComparison.OrdinalIgnoreCase))
                {
                    CheckHostObjectSupport("PreferredUILang", false);
                }
            }
            catch (Exception e)
            {
                if (ExceptionHandling.IsCriticalException(e))
                {
                    throw;
                }

                if (this.HostCompilerSupportsAllParameters)
                {
                    // If the host compiler doesn't support everything we need, we're going to end up 
                    // shelling out to the command-line compiler anyway.  That means the command-line
                    // compiler will log the error.  So here, we only log the error if we would've
                    // tried to use the host compiler.
                    Log.LogErrorWithCodeFromResources("General.CouldNotSetHostObjectParameter", param, e.Message);
                }

                return false;
            }
            finally
            {
                // In the case of the VB host compiler, the EndInitialization method will
                // throw (due to FAILED HRESULT) if there was a bad value for one of the
                // parameters.
                vbcHostObject.EndInitialization();
            }

            return true;
        }
 private bool InitializeHostCompiler(IVbcHostObject vbcHostObject)
 {
     base.HostCompilerSupportsAllParameters = this.UseHostCompilerIfAvailable;
     string parameterName = "Unknown";
     try
     {
         parameterName = "BeginInitialization";
         vbcHostObject.BeginInitialization();
         parameterName = "AdditionalLibPaths";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetAdditionalLibPaths(base.AdditionalLibPaths));
         parameterName = "AddModules";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetAddModules(base.AddModules));
         parameterName = "BaseAddress";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetBaseAddress(base.TargetType, this.GetBaseAddressInHex()));
         parameterName = "CodePage";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetCodePage(base.CodePage));
         parameterName = "DebugType";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDebugType(base.EmitDebugInformation, base.DebugType));
         parameterName = "DefineConstants";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDefineConstants(base.DefineConstants));
         parameterName = "DelaySign";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDelaySign(base.DelaySign));
         parameterName = "DocumentationFile";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDocumentationFile(this.DocumentationFile));
         parameterName = "FileAlignment";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetFileAlignment(base.FileAlignment));
         parameterName = "GenerateDocumentation";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetGenerateDocumentation(this.GenerateDocumentation));
         parameterName = "Imports";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetImports(this.Imports));
         parameterName = "KeyContainer";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetKeyContainer(base.KeyContainer));
         parameterName = "KeyFile";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetKeyFile(base.KeyFile));
         parameterName = "LinkResources";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetLinkResources(base.LinkResources));
         parameterName = "MainEntryPoint";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetMainEntryPoint(base.MainEntryPoint));
         parameterName = "NoConfig";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoConfig(base.NoConfig));
         parameterName = "NoStandardLib";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoStandardLib(this.NoStandardLib));
         parameterName = "NoWarnings";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoWarnings(this.NoWarnings));
         parameterName = "Optimize";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptimize(base.Optimize));
         parameterName = "OptionCompare";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionCompare(this.OptionCompare));
         parameterName = "OptionExplicit";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionExplicit(this.OptionExplicit));
         parameterName = "OptionStrict";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionStrict(this.OptionStrict));
         parameterName = "OptionStrictType";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionStrictType(this.OptionStrictType));
         parameterName = "OutputAssembly";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOutputAssembly(base.OutputAssembly.ItemSpec));
         parameterName = "Platform";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetPlatform(this.Platform));
         parameterName = "References";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetReferences(base.References));
         parameterName = "RemoveIntegerChecks";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetRemoveIntegerChecks(this.RemoveIntegerChecks));
         parameterName = "Resources";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetResources(base.Resources));
         parameterName = "ResponseFiles";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetResponseFiles(base.ResponseFiles));
         parameterName = "RootNamespace";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetRootNamespace(this.RootNamespace));
         parameterName = "SdkPath";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetSdkPath(this.SdkPath));
         parameterName = "Sources";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetSources(base.Sources));
         parameterName = "TargetCompactFramework";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTargetCompactFramework(this.TargetCompactFramework));
         parameterName = "TargetType";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTargetType(base.TargetType));
         parameterName = "TreatWarningsAsErrors";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTreatWarningsAsErrors(base.TreatWarningsAsErrors));
         parameterName = "WarningsAsErrors";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWarningsAsErrors(this.WarningsAsErrors));
         parameterName = "WarningsNotAsErrors";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWarningsNotAsErrors(this.WarningsNotAsErrors));
         parameterName = "DisabledWarnings";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDisabledWarnings(this.DisabledWarnings));
         parameterName = "Win32Icon";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWin32Icon(base.Win32Icon));
         parameterName = "Win32Resource";
         base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWin32Resource(base.Win32Resource));
         if (vbcHostObject is IVbcHostObject2)
         {
             IVbcHostObject2 obj2 = (IVbcHostObject2) vbcHostObject;
             parameterName = "ModuleAssemblyName";
             base.CheckHostObjectSupport(parameterName, obj2.SetModuleAssemblyName(this.ModuleAssemblyName));
             parameterName = "OptionInfer";
             base.CheckHostObjectSupport(parameterName, obj2.SetOptionInfer(this.OptionInfer));
             parameterName = "Win32Manifest";
             base.CheckHostObjectSupport(parameterName, obj2.SetWin32Manifest(base.GetWin32ManifestSwitch(base.NoWin32Manifest, base.Win32Manifest)));
             base.CheckHostObjectSupport("OptionInfer", obj2.SetOptionInfer(this.OptionInfer));
         }
         else
         {
             if (!string.IsNullOrEmpty(this.ModuleAssemblyName))
             {
                 base.CheckHostObjectSupport("ModuleAssemblyName", false);
             }
             if (base.Bag.ContainsKey("OptionInfer"))
             {
                 base.CheckHostObjectSupport("OptionInfer", false);
             }
             if (!string.IsNullOrEmpty(base.Win32Manifest))
             {
                 base.CheckHostObjectSupport("Win32Manifest", false);
             }
         }
         if (vbcHostObject is IVbcHostObject3)
         {
             IVbcHostObject3 obj3 = (IVbcHostObject3) vbcHostObject;
             parameterName = "LangVersion";
             base.CheckHostObjectSupport(parameterName, obj3.SetLanguageVersion(this.LangVersion));
         }
         else if (!string.IsNullOrEmpty(this.LangVersion) && !base.UsedCommandLineTool)
         {
             base.CheckHostObjectSupport("LangVersion", false);
         }
         if (vbcHostObject is IVbcHostObject4)
         {
             IVbcHostObject4 obj4 = (IVbcHostObject4) vbcHostObject;
             parameterName = "VBRuntime";
             base.CheckHostObjectSupport(parameterName, obj4.SetVBRuntime(this.VBRuntime));
         }
         if (this.NoVBRuntimeReference)
         {
             base.CheckHostObjectSupport("NoVBRuntimeReference", false);
         }
     }
     catch (Exception exception)
     {
         if (Microsoft.Build.Shared.ExceptionHandling.IsCriticalException(exception))
         {
             throw;
         }
         if (base.HostCompilerSupportsAllParameters)
         {
             base.Log.LogErrorWithCodeFromResources("General.CouldNotSetHostObjectParameter", new object[] { parameterName, exception.Message });
         }
         return false;
     }
     finally
     {
         vbcHostObject.EndInitialization();
     }
     return true;
 }
Example #6
0
        private bool InitializeHostCompiler(IVbcHostObject vbcHostObject)
        {
            base.HostCompilerSupportsAllParameters = this.UseHostCompilerIfAvailable;
            string parameterName = "Unknown";

            try
            {
                parameterName = "BeginInitialization";
                vbcHostObject.BeginInitialization();
                parameterName = "AdditionalLibPaths";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetAdditionalLibPaths(base.AdditionalLibPaths));
                parameterName = "AddModules";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetAddModules(base.AddModules));
                parameterName = "BaseAddress";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetBaseAddress(base.TargetType, this.GetBaseAddressInHex()));
                parameterName = "CodePage";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetCodePage(base.CodePage));
                parameterName = "DebugType";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDebugType(base.EmitDebugInformation, base.DebugType));
                parameterName = "DefineConstants";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDefineConstants(base.DefineConstants));
                parameterName = "DelaySign";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDelaySign(base.DelaySign));
                parameterName = "DocumentationFile";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDocumentationFile(this.DocumentationFile));
                parameterName = "FileAlignment";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetFileAlignment(base.FileAlignment));
                parameterName = "GenerateDocumentation";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetGenerateDocumentation(this.GenerateDocumentation));
                parameterName = "Imports";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetImports(this.Imports));
                parameterName = "KeyContainer";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetKeyContainer(base.KeyContainer));
                parameterName = "KeyFile";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetKeyFile(base.KeyFile));
                parameterName = "LinkResources";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetLinkResources(base.LinkResources));
                parameterName = "MainEntryPoint";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetMainEntryPoint(base.MainEntryPoint));
                parameterName = "NoConfig";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoConfig(base.NoConfig));
                parameterName = "NoStandardLib";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoStandardLib(this.NoStandardLib));
                parameterName = "NoWarnings";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetNoWarnings(this.NoWarnings));
                parameterName = "Optimize";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptimize(base.Optimize));
                parameterName = "OptionCompare";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionCompare(this.OptionCompare));
                parameterName = "OptionExplicit";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionExplicit(this.OptionExplicit));
                parameterName = "OptionStrict";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionStrict(this.OptionStrict));
                parameterName = "OptionStrictType";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOptionStrictType(this.OptionStrictType));
                parameterName = "OutputAssembly";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetOutputAssembly(base.OutputAssembly.ItemSpec));
                parameterName = "Platform";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetPlatform(this.Platform));
                parameterName = "References";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetReferences(base.References));
                parameterName = "RemoveIntegerChecks";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetRemoveIntegerChecks(this.RemoveIntegerChecks));
                parameterName = "Resources";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetResources(base.Resources));
                parameterName = "ResponseFiles";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetResponseFiles(base.ResponseFiles));
                parameterName = "RootNamespace";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetRootNamespace(this.RootNamespace));
                parameterName = "SdkPath";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetSdkPath(this.SdkPath));
                parameterName = "Sources";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetSources(base.Sources));
                parameterName = "TargetCompactFramework";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTargetCompactFramework(this.TargetCompactFramework));
                parameterName = "TargetType";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTargetType(base.TargetType));
                parameterName = "TreatWarningsAsErrors";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetTreatWarningsAsErrors(base.TreatWarningsAsErrors));
                parameterName = "WarningsAsErrors";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWarningsAsErrors(this.WarningsAsErrors));
                parameterName = "WarningsNotAsErrors";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWarningsNotAsErrors(this.WarningsNotAsErrors));
                parameterName = "DisabledWarnings";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetDisabledWarnings(this.DisabledWarnings));
                parameterName = "Win32Icon";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWin32Icon(base.Win32Icon));
                parameterName = "Win32Resource";
                base.CheckHostObjectSupport(parameterName, vbcHostObject.SetWin32Resource(base.Win32Resource));
                if (vbcHostObject is IVbcHostObject2)
                {
                    IVbcHostObject2 obj2 = (IVbcHostObject2)vbcHostObject;
                    parameterName = "ModuleAssemblyName";
                    base.CheckHostObjectSupport(parameterName, obj2.SetModuleAssemblyName(this.ModuleAssemblyName));
                    parameterName = "OptionInfer";
                    base.CheckHostObjectSupport(parameterName, obj2.SetOptionInfer(this.OptionInfer));
                    parameterName = "Win32Manifest";
                    base.CheckHostObjectSupport(parameterName, obj2.SetWin32Manifest(base.GetWin32ManifestSwitch(base.NoWin32Manifest, base.Win32Manifest)));
                    base.CheckHostObjectSupport("OptionInfer", obj2.SetOptionInfer(this.OptionInfer));
                }
                else
                {
                    if (!string.IsNullOrEmpty(this.ModuleAssemblyName))
                    {
                        base.CheckHostObjectSupport("ModuleAssemblyName", false);
                    }
                    if (base.Bag.ContainsKey("OptionInfer"))
                    {
                        base.CheckHostObjectSupport("OptionInfer", false);
                    }
                    if (!string.IsNullOrEmpty(base.Win32Manifest))
                    {
                        base.CheckHostObjectSupport("Win32Manifest", false);
                    }
                }
                if (vbcHostObject is IVbcHostObject3)
                {
                    IVbcHostObject3 obj3 = (IVbcHostObject3)vbcHostObject;
                    parameterName = "LangVersion";
                    base.CheckHostObjectSupport(parameterName, obj3.SetLanguageVersion(this.LangVersion));
                }
                else if (!string.IsNullOrEmpty(this.LangVersion) && !base.UsedCommandLineTool)
                {
                    base.CheckHostObjectSupport("LangVersion", false);
                }
                if (vbcHostObject is IVbcHostObject4)
                {
                    IVbcHostObject4 obj4 = (IVbcHostObject4)vbcHostObject;
                    parameterName = "VBRuntime";
                    base.CheckHostObjectSupport(parameterName, obj4.SetVBRuntime(this.VBRuntime));
                }
                if (this.NoVBRuntimeReference)
                {
                    base.CheckHostObjectSupport("NoVBRuntimeReference", false);
                }
            }
            catch (Exception exception)
            {
                if (Microsoft.Build.Shared.ExceptionHandling.IsCriticalException(exception))
                {
                    throw;
                }
                if (base.HostCompilerSupportsAllParameters)
                {
                    base.Log.LogErrorWithCodeFromResources("General.CouldNotSetHostObjectParameter", new object[] { parameterName, exception.Message });
                }
                return(false);
            }
            finally
            {
                vbcHostObject.EndInitialization();
            }
            return(true);
        }