private static bool IsProjectNuGetPackage(SolutionProject project) { Log.InfoFormat("Checking if project {0} is a NuGet package project", project.ProjectName); string projectPath = Path.Combine(SolutionFolder, project.RelativePath); Log.InfoFormat("Calculated projectPath = {0}", projectPath); return(IsProjectNuGetPackage(projectPath)); }
private static void RemoveNuGetDependencies(SolutionProject project) { string projFilePath = Path.Combine(SolutionFolder, project.RelativePath); string nuspecPath = GetExpectedNuGetFileFullPath(projFilePath); XDocument nuspecDocument = XDocument.Load(nuspecPath); XElement dependenciesElement = nuspecDocument.Descendants("dependencies").SingleOrDefault(); if (dependenciesElement != null) { dependenciesElement.Remove(); nuspecDocument.Save(nuspecPath); } }
private static void EnsureProjectIsNugetDependency(string projFilePath, XElement dependencyToAdd, SolutionProject dependentProject) { var dependentProjectNuspecPath = GetExpectedNuGetFileFullPath(projFilePath); var dependencyProjectNuspecPath = GetNuspecPath(Path.GetDirectoryName(projFilePath), dependencyToAdd); string packageId = GetNuGetPackageId(dependencyProjectNuspecPath); XDocument nuspecDocument = XDocument.Load(dependentProjectNuspecPath); // First get the dependencies node XElement dependenciesElement = nuspecDocument.Descendants("dependencies").SingleOrDefault(); if (dependenciesElement == null) { XElement metadataElement = nuspecDocument.Descendants("metadata").SingleOrDefault(); if (metadataElement == null) { throw new ArgumentException( "Invalid nuspec file. It is missing its metadata element"); } dependenciesElement = new XElement("dependencies", new XElement("dependency", new XAttribute("id", packageId), new XAttribute("version", ReleaseVersion))); metadataElement.Add(dependenciesElement); } else { XElement dependencyElement = dependenciesElement.Elements("dependency").SingleOrDefault( element => element.Attribute("id").Value == packageId); if (dependencyElement != null) { dependencyElement.Attribute("version").Value = ReleaseVersion; } else { dependencyElement = new XElement("dependency", new XAttribute("id", packageId), new XAttribute("version", ReleaseVersion)); dependenciesElement.Add(dependencyElement); } } nuspecDocument.Save(dependentProjectNuspecPath); }