Beispiel #1
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));
        }
Beispiel #2
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 = false;
                //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);
                _outputs.Add(output);

                // See if it is our key output
                if (_keyOutput == null ||
                    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);
        }