Example #1
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildObject ob = null;

            switch (reader.LocalName)
            {
            case "ItemGroup": ob = new MSBuildItemGroup(); break;

            case "PropertyGroup": ob = new MSBuildPropertyGroup(); break;

            case "ImportGroup": ob = new MSBuildImportGroup(); break;

            case "Import": ob = new MSBuildImport(); break;

            case "Target": ob = new MSBuildTarget(); break;

            case "Choose": ob = new MSBuildChoose(); break;

            case "ProjectExtensions": ob = new MSBuildProjectExtensions(); break;

            default: ob = new MSBuildXmlElement(); break;
            }
            if (ob != null)
            {
                ob.ParentNode = this;
                ob.Read(reader);
                ChildNodes = ChildNodes.Add(ob);
            }
            else
            {
                base.ReadChildElement(reader);
            }
        }
		static bool IsMatch (MSBuildImport import, string importsRelativeDirectory)
		{
			if (String.IsNullOrEmpty (import.Project))
				return false;

			return import.Project.StartsWith (importsRelativeDirectory, StringComparison.OrdinalIgnoreCase);
		}
        public MSBuildImport AddNewImport(string name, string condition = null, MSBuildImport beforeImport = null)
        {
            AssertCanModify();
            var import = new MSBuildImport();

            import.Project   = name;
            import.Condition = condition;

            int insertIndex = -1;

            if (beforeImport != null)
            {
                insertIndex = ChildNodes.IndexOf(beforeImport);
            }

            if (insertIndex != -1)
            {
                ChildNodes = ChildNodes.Insert(insertIndex, import);
            }
            else
            {
                ChildNodes = ChildNodes.Add(import);
            }

            import.ResetIndent(false);
            NotifyChanged();
            return(import);
        }
Example #4
0
        void ImportFile(ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string file)
        {
            if (!File.Exists(file))
            {
                return;
            }

            var pref = LoadProject(file);

            project.ReferencedProjects.Add(pref);

            var prefProject = new ProjectInfo {
                Project = pref
            };

            AddImportedProject(project, import, prefProject);

            var refCtx = new MSBuildEvaluationContext(context);

            EvaluateProject(prefProject, refCtx, false);

            foreach (var p in prefProject.Properties)
            {
                p.Value.IsImported         = true;
                project.Properties [p.Key] = p.Value;
            }
        }
		public void RemoveImport (MSBuildImport import)
		{
			AssertCanModify ();
			if (import.ParentObject == this) {
				import.RemoveIndent ();
				ChildNodes = ChildNodes.Remove (import);
				NotifyChanged ();
			}
		}
 public void RemoveImport(MSBuildImport import)
 {
     AssertCanModify();
     if (import.ParentObject == this)
     {
         import.RemoveIndent();
         ChildNodes = ChildNodes.Remove(import);
         NotifyChanged();
     }
 }
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			if (reader.LocalName == "Import") {
				var item = new MSBuildImport ();
				item.ParentNode = this;
				item.Read (reader);
				ChildNodes = ChildNodes.Add (item);
			} else
				base.ReadChildElement (reader);
		}
Example #8
0
        IEnumerable <ProjectInfo> GetImportedProjects(ProjectInfo project, MSBuildImport import)
        {
            List <ProjectInfo> prefProjects;

            if (project.ImportedProjects.TryGetValue(import, out prefProjects))
            {
                return(prefProjects);
            }
            return(Enumerable.Empty <ProjectInfo> ());
        }
Example #9
0
        void AddImportedProject(ProjectInfo project, MSBuildImport import, ProjectInfo imported)
        {
            List <ProjectInfo> prefProjects;

            if (!project.ImportedProjects.TryGetValue(import, out prefProjects))
            {
                project.ImportedProjects [import] = prefProjects = new List <ProjectInfo> ();
            }
            prefProjects.Add(imported);
        }
        void Evaluate(ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, bool evalItems)
        {
            if (evalItems)
            {
                // Properties have already been evaluated
                // Don't evaluate properties, only items and other elements
                foreach (var p in GetImportedProjects(project, import))
                {
                    EvaluateProject(p, new MSBuildEvaluationContext(context), true);

                    foreach (var it in p.EvaluatedItems)
                    {
                        it.IsImported = true;
                        project.EvaluatedItems.Add(it);
                    }
                    foreach (var it in p.EvaluatedItemsIgnoringCondition)
                    {
                        it.IsImported = true;
                        project.EvaluatedItemsIgnoringCondition.Add(it);
                    }
                    foreach (var t in p.Targets)
                    {
                        t.IsImported = true;
                        project.Targets.Add(t);
                    }
                    foreach (var cp in p.ConditionedProperties)
                    {
                        foreach (var v in cp.Value)
                        {
                            project.ConditionedProperties.AddProperty(cp.Key, v);
                        }
                    }
                }
                return;
            }

            // For some reason, Mono can have several extension paths, so we need to try each of them
            foreach (var ep in MSBuildEvaluationContext.GetApplicableExtensionsPaths())
            {
                var files = GetImportFiles(project, context, import, ep);
                if (files == null || files.Length == 0)
                {
                    continue;
                }
                foreach (var f in files)
                {
                    ImportFile(project, context, import, f);
                }
                return;
            }

            // No import was found
        }
Example #11
0
 internal override void ReadChildElement(MSBuildXmlReader reader)
 {
     if (reader.LocalName == "Import")
     {
         var item = new MSBuildImport();
         item.ParentNode = this;
         item.Read(reader);
         ChildNodes = ChildNodes.Add(item);
     }
     else
     {
         base.ReadChildElement(reader);
     }
 }
Example #12
0
        public void RemoveImport(MSBuildImport import)
        {
            AssertCanModify();
            if (import.ParentProject != this)
            {
                throw new InvalidOperationException("Import object does not belong to this project");
            }

            if (import.ParentObject == this)
            {
                import.RemoveIndent();
                ChildNodes = ChildNodes.Remove(import);
                NotifyChanged();
            }
            else
            {
                ((MSBuildImportGroup)import.ParentObject).RemoveImport(import);
            }
        }
		public MSBuildImport AddNewImport (string name, string condition = null, MSBuildImport beforeImport = null)
		{
			AssertCanModify ();
			var import = new MSBuildImport ();
			import.Project = name;
			import.Condition = condition;

			int insertIndex = -1;
			if (beforeImport != null)
				insertIndex = ChildNodes.IndexOf (beforeImport);

			if (insertIndex != -1)
				ChildNodes = ChildNodes.Insert (insertIndex, import);
			else
				ChildNodes = ChildNodes.Add (import);

			import.ResetIndent (false);
			NotifyChanged ();
			return import;
		}
Example #14
0
        public MSBuildImport AddNewImport(string name, string condition = null, MSBuildObject beforeObject = null)
        {
            AssertCanModify();
            var import = new MSBuildImport {
                Project   = name,
                Condition = condition
            };

            int index = -1;

            if (beforeObject != null)
            {
                index = ChildNodes.IndexOf(beforeObject);
            }
            else
            {
                index = ChildNodes.FindLastIndex(ob => ob is MSBuildImport);
                if (index != -1)
                {
                    index++;
                }
            }

            import.ParentNode = this;

            if (index != -1)
            {
                ChildNodes = ChildNodes.Insert(index, import);
            }
            else
            {
                ChildNodes = ChildNodes.Add(import);
            }

            import.ResetIndent(false);
            NotifyChanged();
            return(import);
        }
Example #15
0
		void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, bool evalItems)
		{
			if (evalItems) {
				// Properties have already been evaluated
				// Don't evaluate properties, only items and other elements
				foreach (var p in GetImportedProjects (project, import)) {
					
					EvaluateProject (p, new MSBuildEvaluationContext (context), true);

					foreach (var it in p.EvaluatedItems) {
						it.IsImported = true;
						project.EvaluatedItems.Add (it);
					}
					foreach (var it in p.EvaluatedItemsIgnoringCondition) {
						it.IsImported = true;
						project.EvaluatedItemsIgnoringCondition.Add (it);
					}
					foreach (var t in p.Targets) {
						t.IsImported = true;
						project.Targets.Add (t);
					}
					foreach (var t in p.TargetsIgnoringCondition) {
						t.IsImported = true;
						project.TargetsIgnoringCondition.Add (t);
					}
					project.ConditionedProperties.Append (p.ConditionedProperties);
				}
				return;
            }

			// For some reason, Mono can have several extension paths, so we need to try each of them
			foreach (var ep in MSBuildEvaluationContext.GetApplicableExtensionsPaths ()) {
				var files = GetImportFiles (project, context, import, ep);
				if (files == null || files.Length == 0)
					continue;
				foreach (var f in files)
					ImportFile (project, context, import, f);
				return;
			}

			// No import was found
		}
Example #16
0
		string[] GetImportFiles (ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string extensionsPath)
		{
			if (extensionsPath != null) {
				var tempCtx = new MSBuildEvaluationContext (context);
				var mep = MSBuildProjectService.ToMSBuildPath (null, extensionsPath);
				tempCtx.SetPropertyValue ("MSBuildExtensionsPath", mep);
				tempCtx.SetPropertyValue ("MSBuildExtensionsPath32", mep);
				tempCtx.SetPropertyValue ("MSBuildExtensionsPath64", mep);
				context = tempCtx;
			}

			var pr = context.EvaluateString (import.Project);
			project.Imports [import] = pr;

			if (!string.IsNullOrEmpty (import.Condition) && !SafeParseAndEvaluate (project, context, import.Condition, true))
				return null;

			var path = MSBuildProjectService.FromMSBuildPath (project.Project.BaseDirectory, pr);
			var fileName = Path.GetFileName (path);

			if (fileName.IndexOfAny (new [] { '*', '?' }) == -1) {
				return File.Exists (path) ? new [] { path } : null;
			}
			else {
				var files = Directory.GetFiles (Path.GetDirectoryName (path), fileName);
				Array.Sort (files);
				return files;
			}
		}
Example #17
0
		void ImportFile (ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string file)
		{
			if (!File.Exists (file))
				return;
			
			var pref = LoadProject (file);
			project.ReferencedProjects.Add (pref);

			var prefProject = new ProjectInfo { Project = pref };
			AddImportedProject (project, import, prefProject);

			var refCtx = new MSBuildEvaluationContext (context);

			EvaluateProject (prefProject, refCtx, false);

			foreach (var p in prefProject.Properties) {
				p.Value.IsImported = true;
				project.Properties [p.Key] = p.Value;
			}
		}
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			MSBuildObject ob = null;
			switch (reader.LocalName) {
				case "ItemGroup": ob = new MSBuildItemGroup (); break;
				case "PropertyGroup": ob = new MSBuildPropertyGroup (); break;
				case "ImportGroup": ob = new MSBuildImportGroup (); break;
				case "Import": ob = new MSBuildImport (); break;
				case "Target": ob = new MSBuildTarget (); break;
				case "Choose": ob = new MSBuildChoose (); break;
				case "ProjectExtensions": ob = new MSBuildProjectExtensions (); break;
				default: ob = new MSBuildXmlElement (); break;
			}
			if (ob != null) {
				ob.ParentNode = this;
				ob.Read (reader);
				ChildNodes = ChildNodes.Add (ob);
			} else
				base.ReadChildElement (reader);
		}
		public MSBuildImport AddNewImport (string name, string condition = null, MSBuildObject beforeObject = null)
		{
			AssertCanModify ();
			var import = new MSBuildImport {
				Project = name,
				Condition = condition
			};

			int index = -1;
			if (beforeObject != null)
				index = ChildNodes.IndexOf (beforeObject);
			else {
				index = ChildNodes.FindLastIndex (ob => ob is MSBuildImport);
				if (index != -1)
					index++;
			}

			import.ParentNode = this;

			if (index != -1)
				ChildNodes = ChildNodes.Insert (index, import);
			else
				ChildNodes = ChildNodes.Add (import);

			import.ResetIndent (false);
			NotifyChanged ();
			return import;
		}
Example #20
0
		void AddImportedProject (ProjectInfo project, MSBuildImport import, ProjectInfo imported)
		{
			List<ProjectInfo> prefProjects;
			if (!project.ImportedProjects.TryGetValue (import, out prefProjects))
				project.ImportedProjects [import] = prefProjects = new List<ProjectInfo> ();
			prefProjects.Add (imported);
        }
		public void RemoveImport (MSBuildImport import)
		{
			AssertCanModify ();
			if (import.ParentProject != this)
				throw new InvalidOperationException ("Import object does not belong to this project");
			
			if (import.ParentObject == this) {
				import.RemoveIndent ();
				ChildNodes = ChildNodes.Remove (import);
				NotifyChanged ();
			} else
				((MSBuildImportGroup)import.ParentObject).RemoveImport (import);
		}
Example #22
0
        string[] GetImportFiles(ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string extensionsPath)
        {
            if (extensionsPath != null)
            {
                var tempCtx = new MSBuildEvaluationContext(context);
                var mep     = MSBuildProjectService.ToMSBuildPath(null, extensionsPath);
                tempCtx.SetPropertyValue("MSBuildExtensionsPath", mep);
                tempCtx.SetPropertyValue("MSBuildExtensionsPath32", mep);
                tempCtx.SetPropertyValue("MSBuildExtensionsPath64", mep);
                context = tempCtx;
            }

            var pr = context.EvaluateString(import.Project);

            project.Imports [import] = pr;

            if (!string.IsNullOrEmpty(import.Condition) && !SafeParseAndEvaluate(project, context, import.Condition, true))
            {
                return(null);
            }

            var path     = MSBuildProjectService.FromMSBuildPath(project.Project.BaseDirectory, pr);
            var fileName = Path.GetFileName(path);

            if (fileName.IndexOfAny(new [] { '*', '?' }) == -1)
            {
                return(File.Exists(path) ? new [] { path } : null);
            }
            else
            {
                path = Path.GetDirectoryName(path);
                if (!Directory.Exists(path))
                {
                    return(null);
                }
                var files = Directory.GetFiles(path, fileName);
                Array.Sort(files);
                return(files);
            }
        }
Example #23
0
		IEnumerable<ProjectInfo> GetImportedProjects (ProjectInfo project, MSBuildImport import)
		{
			List<ProjectInfo> prefProjects;
			if (project.ImportedProjects.TryGetValue (import, out prefProjects))
				return prefProjects;
			return Enumerable.Empty<ProjectInfo> ();
		}