Example #1
0
 public static string ThreadSafeExpandString(this Microsoft.Build.Evaluation.Project thisp, string path)
 {
     lock (thisp)
     {
         return(thisp.ExpandString(path));
     }
 }
        public static IList<string> GetDependsOnTargetsAsList(this ProjectTargetInstance target,Project project)
        {
            if (target == null) { throw new ArgumentNullException("target"); }
            if (project == null) { throw new ArgumentNullException("project"); }

            List<string> targets = new List<string>();
            string depTargets = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
            string depTargetsEvaluated = project.ExpandString(depTargets);

            string[] dtArray = depTargetsEvaluated.Split(';');
            dtArray.ToList().ForEach(t => {
                if (!string.IsNullOrWhiteSpace(t)) {
                    string tName = t.Trim();
                    if (!string.IsNullOrWhiteSpace(tName) &&
                        string.Compare(";", tName, StringComparison.InvariantCultureIgnoreCase) != 0) {
                        targets.Add(tName);
                    }
                }
            });

            int numTarges = targets != null ? targets.Count() : 0;
            string tempDebug = null;
            if (numTarges >= 1) {
                tempDebug = targets[0];
            }

            return targets;
        }
Example #3
0
 public MSBuildUsing(Project project, ProjectUsingTaskElement pute)
 {
     FileInfo f = new FileInfo(pute.TaskName);
     this.Name = f.Name;
     this.AssemblyFile = pute.AssemblyFile;
     this.TaskFactory = pute.TaskFactory;
     this.Source = project.ExpandString(pute.AssemblyFile);
 }
Example #4
0
        public MSBuildTarget(ProjectTargetInstance pti, Project project, MSBuildFile parent = null)
        {
            this.Target = pti;
            this.Name = pti.Name;
            this.Inputs = pti.Inputs;
            this.Outputs = pti.Outputs;
            this.Location = pti.FullPath;
            this.DependsOnTargets = pti.DependsOnTargets;

            this.TargetColor = "Black";
            this.FontStyle = "Normal";

            if (!string.IsNullOrEmpty(this.Target.Condition))
            {
                this.TargetCondition = this.Target.Condition;
                this.TargetColor = "Gray";
                this.FontStyle = "Italic";
            }

            if (project.Xml.DefaultTargets.Contains(pti.Name))
            {
                this.TargetColor = "MediumBlue";
            }

            if (project.Xml.InitialTargets.Contains(pti.Name))
            {
                this.TargetColor = "LimeGreen";
            }

            if (project.Xml.InitialTargets.Contains(pti.Name) && project.Xml.DefaultTargets.Contains(pti.Name))
            {
                this.TargetColor = "Gold";
            }

            this.Targets = new ObservableCollection<MSBuildTarget>();

            string targets = project.ExpandString(pti.DependsOnTargets);
            targets = this.formatRegex.Replace(targets, string.Empty);
            int i = 0;
            foreach (var target in targets.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                this.Targets.Add(new MSBuildTarget(target));
                i++;
            }

            foreach (var x in project.Xml.Targets.Where(x => x.Name == pti.Name))
            {
                this.BeforeTargets = x.BeforeTargets;
                this.AfterTargets = x.AfterTargets;
            }

            if (parent != null)
            {
                this.Parent = parent;
            }
        }
        private static JObject ProjectToJson(Project project)
        {
            JObject jsonProject = new JObject();
            // Project items like resources, sources and references
            foreach (var item in project.ItemsIgnoringCondition)
            {
                if (jsonProject[item.ItemType] == null)
                {
                    jsonProject[item.ItemType] = new JArray();
                }
                JArray array = (JArray)jsonProject[item.ItemType];

                var jsonItem = new JObject();
                jsonItem["Include"] = item.EvaluatedInclude;
                foreach (var metaData in item.Metadata)
                {
                    jsonItem[metaData.Name] = metaData.EvaluatedValue;
                }
                array.Add(jsonItem);
            }
            // Project properties
            JObject jsonProperties = new JObject();
            foreach (var property in project.AllEvaluatedProperties)
            {
                var value = project.ExpandString(property.EvaluatedValue);
                // Multiple values
                if (value.Contains(";") && value.Contains("\n"))
                {
                    var values = value
                        .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                        .Where(v => !string.IsNullOrWhiteSpace(v))
                        .Select(v => v.Trim());
                    JArray jsonValueArray = new JArray();
                    foreach (var v in values)
                    {
                        jsonValueArray.Add(v);
                    }
                    jsonProperties[property.Name] = jsonValueArray;
                }
                else
                {
                    jsonProperties[property.Name] = value.Trim();
                }
            }
            jsonProject["Properties"] = jsonProperties;
            return jsonProject;
        }
Example #6
0
		public void ExpandString ()
		{
			string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <Foo>What are 'ESCAPE' &amp; ""EVALUATE"" ? $ # % ^</Foo>
    <Bar>y</Bar>
    <Baz Condition=""$(Void)==''"">$(FOO)</Baz>
  </PropertyGroup>
</Project>";
			var reader = XmlReader.Create (new StringReader (xml));
			var root = ProjectRootElement.Create (reader);
			var proj = new Project (root);
			root.FullPath = "ProjectTest.ExpandString.proj";
			Assert.AreEqual ("xyz", proj.ExpandString ("x$(BAR)z"), "#1");
			Assert.AreEqual ("x$(BARz", proj.ExpandString ("x$(BARz"), "#2"); // incomplete
			Assert.AreEqual ("xz", proj.ExpandString ("x@(BAR)z"), "#3"); // not an item
		}
Example #7
0
 string evaluated_value;         // see UpdateEvaluatedValue().
 internal void UpdateEvaluatedValue()
 {
     evaluated_value = Project.ExpandString(UnevaluatedValue);
 }
        protected internal AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> BuildTargetGraph(Project project)
        {
            AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> graph =
                new AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>>();

            foreach (string key in project.Targets.Keys) {
                var target = project.Targets[key];
                if (!graph.ContainsVertex(target)) {
                    graph.AddVertex(target);
                }

                // TODO: DependsOnTargets needs to be evalueated
                string depTargetsString = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;

                List<string> dependentTargets = target.GetDependsOnTargetsAsList(project).ToList();

                string depTargetsStringEvaluated = project.ExpandString(depTargetsString);

                dependentTargets.ToList().ForEach(depTarget => {
                    var dt = project.Targets[depTarget];
                    if (dt != null) {
                        if (!graph.ContainsVertex(dt)) {
                            graph.AddVertex(dt);
                        }

                        Edge<ProjectTargetInstance> e = new Edge<ProjectTargetInstance>(target, dt);
                        graph.AddEdge(e);
                    }
                });
            }

            return graph;
        }