Ejemplo n.º 1
0
        private void RemoveEnsureImportedTarget(string targetsPath)
        {
            dynamic targetElement = null;

            foreach (var target in Project.Xml.Targets)
            {
                if (string.Equals(target.Name, TargetName, StringComparison.OrdinalIgnoreCase))
                {
                    targetElement = target;
                    break;
                }
            }
            if (targetElement == null)
            {
                return;
            }

            var     errorCondition = "!Exists('" + PathUtility.GetPathWithForwardSlashes(targetsPath) + "')";
            dynamic taskElement    = null;

            foreach (var task in targetElement.Tasks)
            {
                // Compare using / for both paths for mono compat.
                var currentCondition = PathUtility.GetPathWithForwardSlashes(task.Condition);

                if (string.Equals(currentCondition, errorCondition, StringComparison.OrdinalIgnoreCase))
                {
                    taskElement = task;
                    break;
                }
            }
            if (taskElement == null)
            {
                return;
            }

            taskElement.Parent.RemoveChild(taskElement);
            if (((System.Collections.ICollection)targetElement.Tasks).Count == 0)
            {
                targetElement.Parent.RemoveChild(targetElement);
            }
        }
Ejemplo n.º 2
0
        public void RemoveImport(string targetFullPath)
        {
            if (targetFullPath == null)
            {
                throw new ArgumentNullException(nameof(targetFullPath));
            }

            var targetRelativePath = PathUtility.GetPathWithForwardSlashes(
                PathUtility.GetRelativePath(
                    PathUtility.EnsureTrailingSlash(ProjectFullPath), targetFullPath));

            if (Project.Xml.Imports != null)
            {
                // search for this import statement and remove it
                dynamic importElement = null;
                foreach (var import in Project.Xml.Imports)
                {
                    var currentPath = PathUtility.GetPathWithForwardSlashes(import.Project);

                    if (StringComparer.OrdinalIgnoreCase.Equals(targetRelativePath, currentPath))
                    {
                        importElement = import;
                        break;
                    }
                }

                if (importElement != null)
                {
                    importElement.Parent.RemoveChild(importElement);
                    RemoveEnsureImportedTarget(targetRelativePath);
                    Project.ReevaluateIfNecessary();
                }
            }

            Project.Save();
        }