public MSBuildProjectInstance(MSBuildProject project)
 {
     msproject = project;
     evaluatedItemsIgnoringCondition = new List <IMSBuildItemEvaluated> ();
     evaluatedProperties             = new MSBuildEvaluatedPropertyCollection(msproject);
     globalProperties = new Dictionary <string, string> (project.GlobalProperties);
 }
Example #2
0
 public MSBuildProjectInstance(MSBuildProject project)
 {
     msproject = project;
     evaluatedItemsIgnoringCondition = new List <IMSBuildItemEvaluated> ();
     evaluatedProperties             = new MSBuildEvaluatedPropertyCollection(msproject);
     if (!project.SolutionDirectory.IsNullOrEmpty)
     {
         globalProperties.Add("SolutionDir", project.SolutionDirectory.ToString() + System.IO.Path.DirectorySeparatorChar);
     }
 }
        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);
        }