Exemplo n.º 1
0
 internal void Sync(MSBuildEngine engine, object item)
 {
     properties.Clear();
     this.engine = engine;
     foreach (var propName in engine.GetItemMetadataNames(item))
     {
         var prop = new MSBuildPropertyEvaluated(ParentProject, propName, engine.GetItemMetadata(item, propName), engine.GetEvaluatedItemMetadata(item, propName));
         properties [propName] = prop;
     }
 }
Exemplo n.º 2
0
        public IMSBuildPropertyEvaluated GetProperty(string name)
        {
            IMSBuildPropertyEvaluated prop;

            if (!properties.TryGetValue(name, out prop))
            {
                if (sourceItem != null)
                {
                    if (engine.GetItemHasMetadata(sourceItem, name))
                    {
                        prop = new MSBuildPropertyEvaluated(ParentProject, name, engine.GetItemMetadata(sourceItem, name), engine.GetEvaluatedItemMetadata(sourceItem, name));
                        properties [name] = prop;
                    }
                }
            }
            return(prop);
        }
        void SyncBuildProject(Dictionary <string, MSBuildItem> currentItems, MSBuildEngine e, object project)
        {
            evaluatedItemsIgnoringCondition.Clear();
            evaluatedItems.Clear();
            evaluatedItemDefinitions?.Clear();

            if (!OnlyEvaluateProperties)
            {
                foreach (var it in e.GetEvaluatedItemDefinitions(project))
                {
                    var xit = it as MSBuildItemEvaluated;
                    if (xit != null)
                    {
                        if (evaluatedItemDefinitions == null)
                        {
                            evaluatedItemDefinitions = new Dictionary <string, MSBuildPropertyGroupEvaluated> ();
                        }
                        MSBuildPropertyGroupEvaluated evalItemDefProps = null;
                        if (!evaluatedItemDefinitions.TryGetValue(xit.Name, out evalItemDefProps))
                        {
                            evalItemDefProps = new MSBuildPropertyGroupEvaluated(msproject);
                            evaluatedItemDefinitions [xit.Name] = evalItemDefProps;
                        }
                        evalItemDefProps.Sync(engine, xit, clearProperties: false);
                    }
                }

                var evalItems = new Dictionary <string, MSBuildItemEvaluated> ();
                foreach (var it in e.GetEvaluatedItems(project))
                {
                    var xit = it as MSBuildItemEvaluated;
                    if (xit == null)
                    {
                        xit = CreateEvaluatedItem(e, it);
                        var itemId = e.GetItemMetadata(it, NodeIdPropertyName);
                        var key    = itemId + " " + xit.Include;
                        if (evalItems.ContainsKey(key))
                        {
                            continue;                             // xbuild seems to return duplicate items when using wildcards. This is a workaround to avoid the duplicates.
                        }
                        MSBuildItem pit;
                        if (!string.IsNullOrEmpty(itemId) && currentItems.TryGetValue(itemId, out pit))
                        {
                            xit.AddSourceItem(pit);
                            xit.Condition   = pit.Condition;
                            evalItems [key] = xit;
                        }
                    }
                    evaluatedItems.Add(xit);
                }

                var evalItemsNoCond = new Dictionary <string, MSBuildItemEvaluated> ();
                foreach (var it in e.GetEvaluatedItemsIgnoringCondition(project))
                {
                    var xit = it as MSBuildItemEvaluated;
                    if (xit == null)
                    {
                        xit = CreateEvaluatedItem(e, it);
                        var itemId = e.GetItemMetadata(it, NodeIdPropertyName);
                        MSBuildItemEvaluated evItem;
                        var key = itemId + " " + xit.Include;
                        if (evalItemsNoCond.ContainsKey(key))
                        {
                            continue;                             // xbuild seems to return duplicate items when using wildcards. This is a workaround to avoid the duplicates.
                        }
                        if (!string.IsNullOrEmpty(itemId) && evalItems.TryGetValue(key, out evItem))
                        {
                            evaluatedItemsIgnoringCondition.Add(evItem);
                            evalItemsNoCond [key] = evItem;
                            continue;
                        }
                        MSBuildItem pit;
                        if (!string.IsNullOrEmpty(itemId) && currentItems.TryGetValue(itemId, out pit))
                        {
                            xit.AddSourceItem(pit);
                            xit.Condition         = pit.Condition;
                            evalItemsNoCond [key] = xit;
                        }
                    }
                    UpdateMetadata(xit);
                    evaluatedItemsIgnoringCondition.Add(xit);
                }

                // Clear the node id metadata
                foreach (var it in evaluatedItems.Concat(evaluatedItemsIgnoringCondition))
                {
                    ((MSBuildPropertyGroupEvaluated)it.Metadata).RemoveProperty(NodeIdPropertyName);
                }

                targets = e.GetTargets(project).ToArray();
                targetsIgnoringCondition = e.GetTargetsIgnoringCondition(project).ToArray();
            }

            var props = new MSBuildEvaluatedPropertyCollection(msproject);

            evaluatedProperties = props;
            props.SyncCollection(e, project);

            conditionedProperties = engine.GetConditionedProperties(project);
        }
		void SyncBuildProject (Dictionary<string,MSBuildItem> currentItems, MSBuildEngine e, object project)
		{
			evaluatedItemsIgnoringCondition.Clear ();
			evaluatedItems.Clear ();

			if (!OnlyEvaluateProperties) {
				
				var evalItems = new Dictionary<string,MSBuildItemEvaluated> ();
				foreach (var it in e.GetEvaluatedItems (project)) {
					var xit = it as MSBuildItemEvaluated;
					if (xit == null) {
						xit = CreateEvaluatedItem (e, it);
						var itemId = e.GetItemMetadata (it, NodeIdPropertyName);
						var key = itemId + " " + xit.Include;
						if (evalItems.ContainsKey (key))
							continue; // xbuild seems to return duplicate items when using wildcards. This is a workaround to avoid the duplicates.
						MSBuildItem pit;
						if (!string.IsNullOrEmpty (itemId) && currentItems.TryGetValue (itemId, out pit)) {
							xit.SourceItem = pit;
							xit.Condition = pit.Condition;
							evalItems [key] = xit;
						}
					}
					evaluatedItems.Add (xit);
				}

				var evalItemsNoCond = new Dictionary<string,MSBuildItemEvaluated> ();
				foreach (var it in e.GetEvaluatedItemsIgnoringCondition (project)) {
					var xit = it as MSBuildItemEvaluated;
					if (xit == null) {
						xit = CreateEvaluatedItem (e, it);
						var itemId = e.GetItemMetadata (it, NodeIdPropertyName);
						MSBuildItemEvaluated evItem;
						var key = itemId + " " + xit.Include;
						if (evalItemsNoCond.ContainsKey (key))
							continue; // xbuild seems to return duplicate items when using wildcards. This is a workaround to avoid the duplicates.
						if (!string.IsNullOrEmpty (itemId) && evalItems.TryGetValue (key, out evItem)) {
							evaluatedItemsIgnoringCondition.Add (evItem);
							evalItemsNoCond [key] = evItem;
							continue;
						}
						MSBuildItem pit;
						if (!string.IsNullOrEmpty (itemId) && currentItems.TryGetValue (itemId, out pit)) {
							xit.SourceItem = pit;
							xit.Condition = pit.Condition;
							evalItemsNoCond [key] = xit;
						}
					}
					evaluatedItemsIgnoringCondition.Add (xit);
				}

				// Clear the node id metadata
				foreach (var it in evaluatedItems.Concat (evaluatedItemsIgnoringCondition))
					((MSBuildPropertyGroupEvaluated)it.Metadata).RemoveProperty (NodeIdPropertyName);

				targets = e.GetTargets (project).ToArray ();
			}

			var props = new MSBuildEvaluatedPropertyCollection (msproject);
			evaluatedProperties = props;
			props.SyncCollection (e, project);

			conditionedProperties = engine.GetConditionedProperties (project);
		}