SetCurrentConfiguration() protected method

Set the configuration in MSBuild. This does not get persisted and is used to evaluate msbuild conditions which are based on the $(Configuration) property.
protected SetCurrentConfiguration ( ) : void
return void
Esempio n. 1
0
        private MSBuild.BuildProperty GetMsBuildProperty(string propertyName, bool resetCache)
        {
            if (resetCache || this.currentConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this.project.SetConfiguration(this.ConfigName);
                this.currentConfig = this.project.BuildProject.EvaluatedProperties;

                project.SetCurrentConfiguration();
            }

            if (this.currentConfig == null)
            {
                throw new Exception("Failed to retrieve properties");
            }

            // return property asked for
            return(this.currentConfig[propertyName]);
        }
Esempio n. 2
0
        protected virtual MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, _PersistStorageType storageType, bool resetCache)
        {
            MSBuildExecution.ProjectInstance requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;
            if (resetCache || requestedConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this._project.SetConfiguration(this.ConfigName, this.Platform);
                this._project.BuildProject.ReevaluateIfNecessary();
                if (this._project.UserBuildProject != null)
                {
                    this._project.UserBuildProject.ReevaluateIfNecessary();
                }

                // Create a snapshot of the evaluated project in its current state
                this.currentConfig = this._project.BuildProject.CreateProjectInstance();
                if (this._project.UserBuildProject != null)
                {
                    this.currentUserConfig = this._project.UserBuildProject.CreateProjectInstance();
                }

                requestedConfig = storageType == _PersistStorageType.PST_PROJECT_FILE ? currentConfig : currentUserConfig;

                // Restore configuration
                _project.SetCurrentConfiguration();
            }

            if (requestedConfig == null)
            {
                if (storageType == _PersistStorageType.PST_PROJECT_FILE)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FailedToRetrieveProperties, CultureInfo.CurrentUICulture), propertyName));
                }

                // user build projects aren't essential
                return(null);
            }

            // return property asked for
            return(requestedConfig.GetProperty(propertyName));
        }
Esempio n. 3
0
        private MSBuildExecution.ProjectPropertyInstance GetMsBuildProperty(string propertyName, bool resetCache)
        {
            if (resetCache || this.currentConfig == null)
            {
                // Get properties for current configuration from project file and cache it
                this.project.SetConfiguration(this.ConfigName);
                this.project.BuildProject.ReevaluateIfNecessary();
                // Create a snapshot of the evaluated project in its current state
                this.currentConfig = this.project.BuildProject.CreateProjectInstance();

                // Restore configuration
                project.SetCurrentConfiguration();
            }

            if (this.currentConfig == null)
            {
                throw new Exception("Failed to retrieve properties");
            }

            // return property asked for
            return(this.currentConfig.GetProperty(propertyName));
        }
Esempio n. 4
0
        protected virtual void Refresh()
        {
            // Let MSBuild know which configuration we are working with
            project.SetConfiguration(projectCfg.ConfigName);

            // Generate dependencies if such a task exist
            const string generateDependencyList = "AllProjectOutputGroups";

            if (project.BuildProject.Targets.ContainsKey(generateDependencyList))
            {
                bool succeeded;
                project.BuildTarget(generateDependencyList, out succeeded);
                Debug.Assert(succeeded, "Failed to build target: " + generateDependencyList);
            }

            // Rebuild the content of our list of output
            string outputType = this.targetName + "Output";

            this.outputs.Clear();
            foreach (MSBuildExecution.ProjectItemInstance assembly in project.CurrentConfig.GetItems(outputType))
            {
                Output output = new Output(project, assembly);
                this.outputs.Add(output);

                // See if it is our key output
                if (String.Compare(assembly.GetMetadataValue("IsKeyOutput"), true.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                {
                    keyOutput = output;
                }
            }

            project.SetCurrentConfiguration();

            // Now that the group is built we have to check if it is invalidated by a property
            // change on the project.
            project.OnProjectPropertyChanged += new EventHandler <ProjectPropertyChangedArgs>(OnProjectPropertyChanged);
        }
Esempio n. 5
0
        protected virtual void Refresh()
        {
            // Let MSBuild know which configuration we are working with
            ThreadHelper.ThrowIfNotOnUIThread();
            _project.SetConfiguration(_projectCfg.ConfigCanonicalName);

            // Generate dependencies if such a task exist
            if (_project.ProjectInstance.Targets.ContainsKey(ProjectFileConstants.AllProjectOutputGroups))
            {
                bool succeeded = false;
                _project.BuildTarget(ProjectFileConstants.AllProjectOutputGroups, out succeeded);
                // The next line triggers an exception for a customer that works with JetBrains.
                //Debug.Assert(succeeded, "Failed to build target: " + ProjectFileConstants.AllProjectOutputGroups);
            }

            // Rebuild the content of our list of output
            string outputType = _targetName + "Output";

            this._outputs.Clear();
            foreach (MSBuildExecution.ProjectItemInstance assembly in MSBuildProjectInstance.GetItems(_project.ProjectInstance, outputType))
            {
                Output output = new Output(_project, assembly);
                this._outputs.Add(output);

                // See if it is our key output
                if (String.Compare(MSBuildItem.GetMetadataValue(assembly, "IsKeyOutput"), true.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                {
                    _keyOutput = output;
                }
            }

            _project.SetCurrentConfiguration();

            // Now that the group is built we have to check if it is invalidated by a property
            // change on the project.
            _project.OnProjectPropertyChanged += new EventHandler <ProjectPropertyChangedArgs>(OnProjectPropertyChanged);
        }