Microsoft.VisualStudio.Project.ProjectConfig.GetMsBuildProperty C# (CSharp) Method

GetMsBuildProperty() private method

private GetMsBuildProperty ( string propertyName, bool resetCache ) : Microsoft.Build.Execution.ProjectPropertyInstance
propertyName string
resetCache bool
return Microsoft.Build.Execution.ProjectPropertyInstance
        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.ConfigKey);
                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);
        }

Usage Example

Esempio n. 1
0
        private string GetPerConfigValue(MSBuild.Project buildProject, bool finalValue, IList <ProjectConfig> configs, bool nullIsFalse)
        {
            string unifiedValue = null;

            for (int i = 0; i < configs.Count; i++)
            {
                ProjectConfig config     = configs[i];
                bool          resetCache = (i == 0);

                // we should be using the buildProject parameter here, but this isn't implemented in MPF
                MSBuild.ProjectProperty buildProperty = config.GetMsBuildProperty(this.propertyName, resetCache);
                string value = this.GetBuildPropertyValue(buildProperty, finalValue);

                if (value != null)
                {
                    value = value.Trim();
                }

                if (nullIsFalse && String.IsNullOrEmpty(value))
                {
                    value = Boolean.FalseString;
                }

                if (i == 0)
                {
                    unifiedValue = value;
                }
                else if (unifiedValue != value)
                {
                    unifiedValue = null; // indicates indeterminate value
                    break;
                }
            }

            return(unifiedValue);
        }