Пример #1
0
        /// <summary>
        /// Iterate over a collection to find an import object matching on path
        /// </summary>
        internal static Import FindFirstMatchingImportByEvaludatedPath(ImportCollection importCollection, string evaluatedPathToMatch)
        {
            foreach (Import import in importCollection)
            {
                if (import.EvaluatedProjectPath.Equals(evaluatedPathToMatch, StringComparison.OrdinalIgnoreCase))
                {
                    return import;
                }
            }

            return null;
        }
Пример #2
0
        /// <summary>
        /// Creates an instance of this class for the given engine, specifying a tools version to
        /// use during builds of this project.
        /// </summary>
        /// <owner>RGoel</owner>
        /// <param name="engine">Engine that will build this project. May be null if the global engine is expected.</param>
        /// <param name="toolsVersion">Tools version to use during builds of this project instance. May be null,
        /// in which case we will use the value in the Project's ToolsVersion attribute, or else the engine
        /// default value.</param>
        public Project
        (
            Engine engine,
            string toolsVersion
        )
        {
#if MSBUILDENABLEVSPROFILING 
            try
            {
                DataCollection.CommentMarkProfile(8808, "Construct Project Using Old OM - Start");
#endif 
#if (!STANDALONEBUILD)
            using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildProjectConstructBegin, CodeMarkerEvent.perfMSBuildProjectConstructEnd))
#endif
            {
                if (engine == null)
                {
                    engine = Engine.GlobalEngine;
                }

                this.parentEngine = engine;
                this.projectId = parentEngine.GetNextProjectId();
                this.projectBuildEventContext = new BuildEventContext(parentEngine.NodeId, BuildEventContext.InvalidTargetId, parentEngine.GetNextProjectId(), BuildEventContext.InvalidTaskId);

                this.isLoadedByHost = true;
                this.buildEnabled = BuildEnabledSetting.UseParentEngineSetting;

                this.isValidated = false;

                // Create a new XML document and add a <Project> element.  This way, the
                // project is always in a valid state from the beginning, and now somebody
                // can start programmatically adding stuff to the <Project>.
                this.mainProjectEntireContents = new XmlDocument();
                this.mainProjectElement = mainProjectEntireContents.CreateElement(XMakeElements.project, XMakeAttributes.defaultXmlNamespace);
                this.mainProjectEntireContents.AppendChild(mainProjectElement);


                // initialize all case-insensitive hash-tables
                this.conditionedPropertiesTable = new Hashtable(StringComparer.OrdinalIgnoreCase);
                this.evaluatedItemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);
                this.evaluatedItemsByNameIgnoringCondition = new Hashtable(StringComparer.OrdinalIgnoreCase);

                // Create the group collection.  All collection elements are stored here.
                this.rawGroups = new GroupingCollection(null /* null parent means this is the master collection */);

                // Initialize all property-related objects.
                // (see above for initialization of this.conditionedPropertiesTable)
                this.globalProperties = null;
                this.environmentProperties = null;
                this.reservedProperties = null;
                // We still create the rawPropertyGroups collection, but
                // it's just a facade over rawGroups
                this.rawPropertyGroups = new BuildPropertyGroupCollection(this.rawGroups);
                this.evaluatedProperties = new BuildPropertyGroup();

                // Initialize all item-related objects.
                // (see above for initialization of this.evaluatedItemsByName and this.evaluatedItemsByNameIgnoringCondition
                // We still create the rawItemGroups collection, but it's just a facade over rawGroups
                this.rawItemGroups = new BuildItemGroupCollection(this.rawGroups);
                this.evaluatedItems = new BuildItemGroup();
                this.evaluatedItemsIgnoringCondition = new BuildItemGroup();

                this.itemDefinitionLibrary = new ItemDefinitionLibrary(this);

                // Initialize all target- and task-related objects.
                this.usingTasks = new UsingTaskCollection();
                this.imports = new ImportCollection(this);
                this.taskRegistry = new TaskRegistry();
                this.targets = new TargetCollection(this);

                // Initialize the default targets, initial targets, and project file name.
                this.defaultTargetNames = new string[0];
                this.initialTargetNamesInMainProject = new ArrayList();
                this.initialTargetNamesInImportedProjects = new ArrayList();
                this.FullFileName = String.Empty;
                this.projectDirectory = String.Empty;

                this.projectExtensionsNode = null;

                // If the toolsVersion is null, we will use the value specified in
                // the Project element's ToolsVersion attribute, or else the default if that
                // attribute is not present.
                if (null != toolsVersion)
                {
                    this.ToolsVersion = toolsVersion;
                }

                this.MarkProjectAsDirtyForReprocessXml();
                // The project doesn't really need to be saved yet; there's nothing in it!
                this.dirtyNeedToSaveProjectFile = false;
                this.IsReset = false;

                // Grab some initial properties from the Engine.
                // Global properties and reserved properties need to be cloned, because
                // different projects may have different sets of properties or values
                // for these.  Environment properties don't have to be cloned, because
                // the environment is captured once at engine instantiation, and
                // shared by all projects thereafter.
                this.GlobalProperties = this.parentEngine.GlobalProperties;
                this.EnvironmentProperties = this.parentEngine.EnvironmentProperties;
            }
#if MSBUILDENABLEVSPROFILING 
            }
            finally
            {
                DataCollection.CommentMarkProfile(8809, "Construct Project Using Old OM - End");
            }
#endif
        }
Пример #3
0
        /// <summary>
        /// Search import collection and return the matched Import object
        /// </summary>
        internal static Import GetImportByProjectPath(ImportCollection imports, string projPath)
        {
            foreach (Import import in imports)
            {
                if (import.ProjectPath == projPath)
                {
                    return import;           
                }
            }

            return null;
        }