Inheritance: System.CodeDom.Compiler.CompilerParameters
コード例 #1
0
ファイル: ProjectNode.cs プロジェクト: mimura1133/vstex
        /// <summary>
        ///     Set the configuration property in MSBuild.
        ///     This does not get persisted and is used to evaluate msbuild conditions
        ///     which are based on the $(Configuration) property.
        /// </summary>
        /// <param name="config">Configuration name</param>
        protected internal virtual void SetConfiguration(string config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Can't ask for the active config until the project is opened, so do nothing in that scenario
            if (!HasProjectOpened)
                return;

            // We cannot change properties during the build so if the config
            // we want to set is the current, we do nothing otherwise we fail.
            if (BuildInProgress)
            {
                var automationObject = GetAutomationObject() as EnvDTE.Project;
                var currentConfigName = Utilities.GetActiveConfigurationName(automationObject);
                var configsAreEqual = string.Compare(currentConfigName, config, StringComparison.OrdinalIgnoreCase) == 0;

                if (configsAreEqual)
                {
                    return;
                }
                throw new InvalidOperationException();
            }

            var propertiesChanged = buildProject.SetGlobalProperty(ProjectFileConstants.Configuration, config);
            if (CurrentConfig == null || propertiesChanged)
            {
                CurrentConfig = buildProject.CreateProjectInstance();
            }

            if (propertiesChanged || designTimeAssemblyResolution == null)
            {
                if (designTimeAssemblyResolution == null)
                {
                    designTimeAssemblyResolution = new DesignTimeAssemblyResolution();
                }

                designTimeAssemblyResolution.Initialize(this);
            }

            options = null;
        }
コード例 #2
0
ファイル: ProjectNode.cs プロジェクト: mimura1133/vstex
        public virtual void OnTargetFrameworkMonikerChanged(ProjectOptions options, FrameworkName currentTargetFramework,
            FrameworkName newTargetFramework)
        {
            if (currentTargetFramework == null)
            {
                throw new ArgumentNullException("currentTargetFramework");
            }
            if (newTargetFramework == null)
            {
                throw new ArgumentNullException("newTargetFramework");
            }

            var retargetingService = site.GetService(typeof (SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;
            if (retargetingService == null)
            {
                // Probably in a unit test.
                ////throw new InvalidOperationException("Unable to acquire the SVsTrackProjectRetargeting service.");
                Marshal.ThrowExceptionForHR(UpdateTargetFramework(InteropSafeIVsHierarchy,
                    currentTargetFramework.FullName, newTargetFramework.FullName));
            }
            else
            {
                Marshal.ThrowExceptionForHR(retargetingService.OnSetTargetFramework(InteropSafeIVsHierarchy,
                    currentTargetFramework.FullName, newTargetFramework.FullName, this, true));
            }
        }
コード例 #3
0
ファイル: ProjectNode.cs プロジェクト: mimura1133/vstex
        /// <summary>
        ///     Set configuration properties for a specific configuration
        /// </summary>
        /// <param name="config">configuration name</param>
        protected virtual void SetBuildConfigurationProperties(string config)
        {
            ProjectOptions options = null;

            if (!string.IsNullOrEmpty(config))
            {
                options = GetProjectOptions(config);
            }

            if (options != null && buildProject != null)
            {
                // Make sure the project configuration is set properly
                SetConfiguration(config);
            }
        }
コード例 #4
0
ファイル: ProjectNode.cs プロジェクト: mimura1133/vstex
        public virtual ProjectOptions GetProjectOptions(string config = null)
        {
            if (string.IsNullOrEmpty(config))
            {
                var automationObject = GetAutomationObject() as EnvDTE.Project;
                try
                {
                    config = Utilities.GetActiveConfigurationName(automationObject);
                }
                catch (InvalidOperationException)
                {
                    // Can't figure out the active configuration.  Perhaps during solution load, or in a unit test.
                }
                catch (COMException)
                {
                    // We may be in solution load and don't have an active config yet.
                }
            }

            // Even though the options are the same, when this config was originally set, it may have been before 
            // the project system was ready to set up its configuration, so go ahead and call through to SetConfiguration 
            // anyway -- it should do effectively nothing if the config is the same and all the initialization has 
            // already occurred. 
            if (this.options != null && string.Equals(this.options.Config, config, StringComparison.OrdinalIgnoreCase))
            {
                if (config != null)
                {
                    // Fancy dance with the options required because SetConfiguration nulls out this.options 
                    // even if the configuration itself has not changed; whereas we're only calling SetConfiguration 
                    // for purposes of initializing some other fields here; since we know the config is the same, it
                    // should be perfectly safe to keep the same options as before.  
                    var currentOptions = this.options;
                    SetConfiguration(config);
                    this.options = currentOptions;
                }

                return this.options;
            }

            var options = CreateProjectOptions();
            options.Config = config;

            var targetFrameworkMoniker = GetProjectProperty("TargetFrameworkMoniker", false);

            if (!string.IsNullOrEmpty(targetFrameworkMoniker))
            {
                try
                {
                    options.TargetFrameworkMoniker = new FrameworkName(targetFrameworkMoniker);
                }
                catch (ArgumentException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
            }

            if (config == null)
            {
                this.options = options;
                return options;
            }

            options.GenerateExecutable = true;

            SetConfiguration(config);

            var outputPath = GetOutputPath(CurrentConfig);
            if (!string.IsNullOrEmpty(outputPath))
            {
                // absolutize relative to project folder location
                outputPath = Path.Combine(ProjectFolder, outputPath);
            }

            // Set some default values
            options.OutputAssembly = outputPath + Caption + ".exe";
            options.ModuleKind = ModuleKindFlags.ConsoleApplication;

            options.RootNamespace = GetProjectProperty(ProjectFileConstants.RootNamespace, false);
            options.OutputAssembly = outputPath + GetAssemblyName(config);

            var outputtype = GetProjectProperty(ProjectFileConstants.OutputType, false);
            if (!string.IsNullOrEmpty(outputtype))
            {
                outputtype = outputtype.ToLower(CultureInfo.InvariantCulture);
            }

            if (outputtype == "library")
            {
                options.ModuleKind = ModuleKindFlags.DynamicallyLinkedLibrary;
                options.GenerateExecutable = false; // DLL's have no entry point.
            }
            else if (outputtype == "winexe")
                options.ModuleKind = ModuleKindFlags.WindowsApplication;
            else
                options.ModuleKind = ModuleKindFlags.ConsoleApplication;

            options.Win32Icon = GetProjectProperty("ApplicationIcon", false);
            options.MainClass = GetProjectProperty("StartupObject", false);

            //    other settings from CSharp we may want to adopt at some point...
            //    AssemblyKeyContainerName = ""  //This is the key file used to sign the interop assembly generated when importing a com object via add reference
            //    AssemblyOriginatorKeyFile = ""
            //    DelaySign = "false"
            //    DefaultClientScript = "JScript"
            //    DefaultHTMLPageLayout = "Grid"
            //    DefaultTargetSchema = "IE50"
            //    PreBuildEvent = ""
            //    PostBuildEvent = ""
            //    RunPostBuildEvent = "OnBuildSuccess"

            // transfer all config build options...
            if (GetBoolAttr(CurrentConfig, "AllowUnsafeBlocks"))
            {
                options.AllowUnsafeCode = true;
            }

            if (GetProjectProperty("BaseAddress", false) != null)
            {
                try
                {
                    options.BaseAddress = long.Parse(GetProjectProperty("BaseAddress", false),
                        CultureInfo.InvariantCulture);
                }
                catch (ArgumentNullException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (ArgumentException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (FormatException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (OverflowException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
            }

            if (GetBoolAttr(CurrentConfig, "CheckForOverflowUnderflow"))
            {
                options.CheckedArithmetic = true;
            }

            if (GetProjectProperty("DefineConstants", false) != null)
            {
                options.DefinedPreprocessorSymbols = new StringCollection();
                foreach (var s in GetProjectProperty("DefineConstants", false).Replace(" \t\r\n", "").Split(';'))
                {
                    options.DefinedPreprocessorSymbols.Add(s);
                }
            }

            var docFile = GetProjectProperty("DocumentationFile", false);
            if (!string.IsNullOrEmpty(docFile))
            {
                options.XmlDocFileName = Path.Combine(ProjectFolder, docFile);
            }

            if (GetBoolAttr(CurrentConfig, "DebugSymbols"))
            {
                options.IncludeDebugInformation = true;
            }

            if (GetProjectProperty("FileAlignment", false) != null)
            {
                try
                {
                    options.FileAlignment = int.Parse(GetProjectProperty("FileAlignment", false),
                        CultureInfo.InvariantCulture);
                }
                catch (ArgumentNullException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (ArgumentException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (FormatException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (OverflowException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
            }

            if (GetBoolAttr(CurrentConfig, "IncrementalBuild"))
            {
                options.IncrementalCompile = true;
            }

            if (GetBoolAttr(CurrentConfig, "Optimize"))
            {
                options.Optimize = true;
            }

            if (GetBoolAttr(CurrentConfig, "RegisterForComInterop"))
            {
            }

            if (GetBoolAttr(CurrentConfig, "RemoveIntegerChecks"))
            {
            }

            if (GetBoolAttr(CurrentConfig, "TreatWarningsAsErrors"))
            {
                options.TreatWarningsAsErrors = true;
            }

            if (GetProjectProperty("WarningLevel", false) != null)
            {
                try
                {
                    options.WarningLevel = int.Parse(GetProjectProperty("WarningLevel", false),
                        CultureInfo.InvariantCulture);
                }
                catch (ArgumentNullException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (ArgumentException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (FormatException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
                catch (OverflowException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);
                }
            }

            this.options = options; // do this AFTER setting configuration so it doesn't clear it.
            return options;
        }