Ejemplo n.º 1
0
 private void AddImportStatementForVS2013(ProjectImportLocation location, string relativeTargetPath)
 {
     NuGet.VisualStudio12.ProjectHelper.DoWorkInWriterLock(
         Project,
         Project.ToVsHierarchy(),
         buildProject => buildProject.AddImportStatement(relativeTargetPath, location));
 }
Ejemplo n.º 2
0
        public override void AddImport(string targetPath, ProjectImportLocation location)
        {
            if (VsVersionHelper.IsVisualStudio2010)
            {
                base.AddImport(targetPath, location);
            }
            else
            {
                // For VS 2012 or above, the operation has to be done inside the Writer lock
                if (String.IsNullOrEmpty(targetPath))
                {
                    throw new ArgumentNullException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "targetPath");
                }

                string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath);
                if (VsVersionHelper.IsVisualStudio2012)
                {
                    Project.DoWorkInWriterLock(buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location));
                    Project.Save(this);
                }
                else
                {
                    AddImportStatementForVS2013(location, relativeTargetPath);
                }
            }
        }
Ejemplo n.º 3
0
        public override void AddImport(string targetPath, ProjectImportLocation location)
        {
            if (VsVersionHelper.IsVisualStudio2010)
            {
                base.AddImport(targetPath, location);
            }
            else
            {
                // For VS 2012 or above, the operation has to be done inside the Writer lock
                if (String.IsNullOrEmpty(targetPath))
                {
                    throw new ArgumentNullException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "targetPath");
                }

                string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath);
                if (VsVersionHelper.IsVisualStudio2012)
                {
                    Project.DoWorkInWriterLock(buildProject => buildProject.AddImportStatement(relativeTargetPath, location));
                    Project.Save(this);
                }
                else
                {
                    AddImportStatementForVS2013(location, relativeTargetPath);
                }
            }
        }
Ejemplo n.º 4
0
        public void AddImport(string targetPath, ProjectImportLocation location)
        {
            string relativeTargetPath = GetRelativePath(targetPath);

            project.AddImportIfMissing(relativeTargetPath, location);
            projectService.Save(project);
        }
Ejemplo n.º 5
0
 private void AddImportStatementForVS2013(ProjectImportLocation location, string relativeTargetPath)
 {
     NuGet.VisualStudio12.ProjectHelper.DoWorkInWriterLock(
         Project,
         Project.ToVsHierarchy(),
         buildProject => buildProject.AddImportStatement(relativeTargetPath, location));
 }
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     GuiSyncDispatch(() => {
         string relativeTargetPath = GetRelativePath(targetPath);
         project.AddImportIfMissing(relativeTargetPath, null);
         project.Save();
     });
 }
Ejemplo n.º 7
0
		public static void AddImport (
			this MSBuildProject project,
			string importedProjectFile,
			ProjectImportLocation importLocation,
			string condition)
		{
			XmlElement import = project.AddImportElement (importedProjectFile, importLocation);
			import.SetAttribute ("Condition", condition);
		}
Ejemplo n.º 8
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     GuiSyncDispatch(async() => {
         string relativeTargetPath = GetRelativePath(targetPath);
         string condition          = GetCondition(relativeTargetPath);
         project.AddImportIfMissing(relativeTargetPath, condition);
         await project.SaveAsync();
     });
 }
		public static void AddImport (
			this MSBuildProject project,
			string importedProjectFile,
			ProjectImportLocation importLocation,
			string condition)
		{
			var before = importLocation == ProjectImportLocation.Top ? project.GetAllObjects ().FirstOrDefault () : null;
			project.AddNewImport (importedProjectFile, condition, before);
		}
Ejemplo n.º 10
0
        private void AddImportStatementForVS2013(ProjectImportLocation location, string relativeTargetPath)
        {
            NuGetVS.ProjectHelper.DoWorkInWriterLock(
                Project,
                Project.ToVsHierarchy(),
                buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location));

            // notify the project system of the change
            UpdateImportStamp(Project);
        }
		static ProjectImportElement AddImport(
			ProjectRootElement projectRoot,
			string importedProjectFile,
			ProjectImportLocation importLocation)
		{
			if (importLocation == ProjectImportLocation.Top) {
				return AddImportAtTop(projectRoot, importedProjectFile);
			}
			return projectRoot.AddImport(importedProjectFile);
		}
        public static void AddImport(
            this MSBuildProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation,
            string condition)
        {
            XmlElement import = project.AddImportElement(importedProjectFile, importLocation);

            import.SetAttribute("Condition", condition);
        }
Ejemplo n.º 13
0
        private void AddImportStatementForVS2013(ProjectImportLocation location, string relativeTargetPath)
        {
            NuGet.VisualStudio12.ProjectHelper.DoWorkInWriterLock(
                Project,
                Project.ToVsHierarchy(),
                buildProject => NuGet.MSBuildProjectUtility.AddImportStatement(buildProject, relativeTargetPath, location));

            // notify the project system of the change
            UpdateImportStamp(Project);
        }
Ejemplo n.º 14
0
        public static void AddImport(
            this MSBuildProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation,
            string condition)
        {
            var before = importLocation == ProjectImportLocation.Top ? project.GetAllObjects().FirstOrDefault() : null;

            project.AddNewImport(importedProjectFile, condition, before);
        }
 public static void AddImportIfMissing(
     this DotNetProject project,
     string importedProjectFile,
     ProjectImportLocation importLocation)
 {
     var msbuildProject = new MSBuildProject ();
     msbuildProject.Load (project.FileName);
     msbuildProject.AddImportIfMissing (importedProjectFile, importLocation, GetCondition (importedProjectFile));
     msbuildProject.Save (project.FileName);
 }
Ejemplo n.º 16
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     if (location == ProjectImportLocation.Top)
     {
         _topImports.Add(targetPath);
     }
     else
     {
         _bottomImports.Add(targetPath);
     }
 }
Ejemplo n.º 17
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     GuiSyncDispatch(async() => {
         string relativeTargetPath = GetRelativePath(targetPath);
         string condition          = GetCondition(relativeTargetPath);
         using (var handler = CreateNewImportsHandler()) {
             handler.AddImportIfMissing(relativeTargetPath, condition, location);
             await project.SaveAsync();
         }
     });
 }
 static ProjectImportElement AddImport(
     ProjectRootElement projectRoot,
     string importedProjectFile,
     ProjectImportLocation importLocation)
 {
     if (importLocation == ProjectImportLocation.Top)
     {
         return(AddImportAtTop(projectRoot, importedProjectFile));
     }
     return(projectRoot.AddImport(importedProjectFile));
 }
 public bool ImportExists(string targetPath, ProjectImportLocation location)
 {
     if (location == ProjectImportLocation.Top)
     {
         return(_topImports.Contains(targetPath));
     }
     else
     {
         return(_bottomImports.Contains(targetPath));
     }
 }
Ejemplo n.º 20
0
        public static void AddImportIfMissing(
            this DotNetProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation)
        {
            var msbuildProject = new MSBuildProject();

            msbuildProject.Load(project.FileName);
            msbuildProject.AddImportIfMissing(importedProjectFile, importLocation, GetCondition(importedProjectFile));
            msbuildProject.Save(project.FileName);
        }
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     if (location == ProjectImportLocation.Top)
     {
         _topImports.Add(targetPath);
     }
     else
     {
         _bottomImports.Add(targetPath);
     }
 }
Ejemplo n.º 22
0
		public static void AddImportIfMissing (
			this MSBuildProject project,
			string importedProjectFile,
			ProjectImportLocation importLocation,
			string condition)
		{
			if (project.ImportExists (importedProjectFile))
				return;
			
			project.AddImport (importedProjectFile, importLocation, condition);
		}
Ejemplo n.º 23
0
        public void AddImport(string targetFullPath, ProjectImportLocation location)
        {
            if (targetFullPath == null)
            {
                throw new ArgumentNullException("targetFullPath");
            }

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

            NuGet.MSBuildProjectUtility.AddImportStatement(Project, targetRelativePath, location);
            Project.Save();
        }
Ejemplo n.º 24
0
		static XmlElement AddImportElement(
			this MSBuildProject project,
			string importedProjectFile,
			ProjectImportLocation importLocation)
		{
			if (importLocation == ProjectImportLocation.Top) {
				return project.AddImportElementAtTop (importedProjectFile);
			}
			XmlElement import = project.CreateImportElement (importedProjectFile);
			project.Document.DocumentElement.AppendChild (import);
			return import;
		}
Ejemplo n.º 25
0
        public virtual void AddImport(string targetPath, ProjectImportLocation location)
        {
            if (String.IsNullOrEmpty(targetPath))
            {
                throw new ArgumentNullException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "targetPath");
            }

            string relativeTargetPath = PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(Root), targetPath);

            Project.AddImportStatement(relativeTargetPath, location);
            Project.Save(this);
        }
		public static void AddImportIfMissing(
			this MSBuildBasedProject project,
			string importedProjectFile,
			ProjectImportLocation importLocation)
		{
			lock (project.SyncRoot) {
				if (project.ImportExists(importedProjectFile))
					return;
				
				ProjectImportElement import = AddImport(project.MSBuildProjectFile, importedProjectFile, importLocation);
				import.Condition = GetCondition(importedProjectFile);
			}
		}
Ejemplo n.º 27
0
        public static void AddImportIfMissing(
            this MSBuildProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation,
            string condition)
        {
            if (project.ImportExists(importedProjectFile))
            {
                return;
            }

            project.AddImport(importedProjectFile, importLocation, condition);
        }
        static XmlElement AddImportElement(
            this MSBuildProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation)
        {
            if (importLocation == ProjectImportLocation.Top)
            {
                return(project.AddImportElementAtTop(importedProjectFile));
            }
            XmlElement import = project.CreateImportElement(importedProjectFile);

            project.Document.DocumentElement.AppendChild(import);
            return(import);
        }
        public static void AddImportIfMissing(
            this MSBuildBasedProject project,
            string importedProjectFile,
            ProjectImportLocation importLocation)
        {
            lock (project.SyncRoot) {
                if (project.ImportExists(importedProjectFile))
                {
                    return;
                }

                ProjectImportElement import = AddImport(project.MSBuildProjectFile, importedProjectFile, importLocation);
                import.Condition = GetCondition(importedProjectFile);
            }
        }
Ejemplo n.º 30
0
        public void AddImport(string targetPath, ProjectImportLocation location)
        {
            if (targetPath == null)
            {
                throw new ArgumentNullException("targetPath");
            }

            // adds an <Import> element to this project file.
            if (Project.Xml.Imports == null ||
                Project.Xml.Imports.All(import => !targetPath.Equals(import.Project, StringComparison.OrdinalIgnoreCase)))
            {
                Project.Xml.AddImport(targetPath);
                Project.ReevaluateIfNecessary();
                Project.Save();
            }
        }
        public void AddImport(string targetFullPath, ProjectImportLocation location)
        {
            if (targetFullPath == null)
            {
                throw new ArgumentNullException("targetFullPath");
            }

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

            // adds an <Import> element to this project file.
            if (Project.Xml.Imports == null ||
                Project.Xml.Imports.All(import => !targetRelativePath.Equals(import.Project, StringComparison.OrdinalIgnoreCase)))
            {
                Project.Xml.AddImport(targetRelativePath);
                NuGet.MSBuildProjectUtility.AddEnsureImportedTarget(Project, targetRelativePath);
                Project.Save();
            }
        }
        /// <summary>
        /// Adds an Import element to this project file if it doesn't already exist.            
        /// </summary>
        /// <param name="project">The project file.</param>
        /// <param name="targetsPath">The path to the imported file.</param>
        /// <param name="location">The location where the Import is added.</param>
        public static void AddImportStatement(MsBuildProject project, string targetsPath, ProjectImportLocation location)
        {
            if (project.Xml.Imports == null ||
                project.Xml.Imports.All(import => !targetsPath.Equals(import.Project, StringComparison.OrdinalIgnoreCase)))
            {
                ProjectImportElement pie = project.Xml.AddImport(targetsPath);
                pie.Condition = "Exists('" + targetsPath + "')";
                if (location == ProjectImportLocation.Top)
                {
                    // There's no public constructor to create a ProjectImportElement directly.
                    // So we have to cheat by adding Import at the end, then remove it and insert at the beginning
                    pie.Parent.RemoveChild(pie);
                    project.Xml.InsertBeforeChild(pie, project.Xml.FirstChild);
                }

                NuGet.MSBuildProjectUtility.AddEnsureImportedTarget(project, targetsPath);
                project.ReevaluateIfNecessary();
            }
        }
Ejemplo n.º 33
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     throw new NotImplementedException("Not supported for websites");
 }
		public void AddImport(string targetPath, ProjectImportLocation location)
		{
			throw new NotSupportedException();
		}
Ejemplo n.º 35
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
 }
Ejemplo n.º 36
0
 public void AddImportIfMissing(string name, string condition, ProjectImportLocation location)
 {
     ImportsAdded.Add(new ImportAndCondition(name, condition, location));
 }
Ejemplo n.º 37
0
 public ImportAndCondition(string name, string condition, ProjectImportLocation location)
 {
     Name      = name;
     Condition = condition;
     Location  = location;
 }
Ejemplo n.º 38
0
        public static void AddImportStatement(this MsBuildProject buildProject, string targetsPath, ProjectImportLocation location)
        {
            // adds an <Import> element to this project file if it doesn't already exist.
            if (buildProject.Xml.Imports == null ||
                buildProject.Xml.Imports.All(import => !targetsPath.Equals(import.Project, StringComparison.OrdinalIgnoreCase)))
            {
                ProjectImportElement pie = buildProject.Xml.AddImport(targetsPath);
                pie.Condition = "Exists('" + targetsPath + "')";

                if (location == ProjectImportLocation.Top)
                {
                    // There's no public constructor to create a ProjectImportElement directly.
                    // So we have to cheat by adding Import at the end, then remove it and insert at the beginning
                    pie.Parent.RemoveChild(pie);
                    buildProject.Xml.InsertBeforeChild(pie, buildProject.Xml.FirstChild);
                }
                else
                {
                    // the import might get added into an ImportGroup. In this case,
                    // we remove it from the ImportGroup and add it at the end of the
                    // project.
                    if (pie.Parent.GetType() == typeof(ProjectImportGroupElement))
                    {
                        pie.Parent.RemoveChild(pie);
                        buildProject.Xml.AppendChild(pie);
                    }
                }

                NuGet.MSBuildProjectUtility.AddEnsureImportedTarget(buildProject, targetsPath);
                buildProject.ReevaluateIfNecessary();
            }
        }
Ejemplo n.º 39
0
 public bool ImportExists(string targetPath, ProjectImportLocation location)
 {
     if (location == ProjectImportLocation.Top)
     {
         return _topImports.Contains(targetPath);
     }
     else
     {
         return _bottomImports.Contains(targetPath);
     }
 }
 public override void AddImport(string targetPath, ProjectImportLocation location)
 {
     // Web sites are not msbuild based and do not support imports.
 }
Ejemplo n.º 41
0
		public void AddImport(string targetPath, ProjectImportLocation location)
		{
			string relativeTargetPath = GetRelativePath(targetPath);
			project.AddImportIfMissing(relativeTargetPath, location);
			ReevaluateProjectIfNecessary();
			projectService.Save(project);
		}
Ejemplo n.º 42
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 43
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
 }
 public void AddImportIfMissing(string name, string condition, ProjectImportLocation location)
 {
     this.name      = name;
     this.condition = condition;
     this.location  = location;
 }
Ejemplo n.º 45
0
        public void AddImport(string targetPath, ProjectImportLocation location)
        {
            if (targetPath == null)
            {
                throw new ArgumentNullException("targetPath");
            }

            // adds an <Import> element to this project file.
            if (Project.Xml.Imports == null ||
                Project.Xml.Imports.All(import => !targetPath.Equals(import.Project, StringComparison.OrdinalIgnoreCase)))
            {
                Project.Xml.AddImport(targetPath);
                Project.ReevaluateIfNecessary();
                Project.Save();
            }
        }
Ejemplo n.º 46
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     // Import statements do not apply to WebMatrix
     throw new NotImplementedException();
 }
 public void AddImport(string targetFullPath, ProjectImportLocation location)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 48
0
 public static void AddImportStatement(this Project project, string targetsPath, ProjectImportLocation location)
 {
     NuGet.MSBuildProjectUtility.AddImportStatement(project.AsMSBuildProject(), targetsPath, location);
 }
Ejemplo n.º 49
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     // Import statements do not apply to WebMatrix
     throw new NotImplementedException();
 }
Ejemplo n.º 50
0
 public void AddImport(string targetPath, ProjectImportLocation location)
 {
     throw new NotImplementedException("Not supported for websites");
 }