public void NuspecFileShouldHaveValuesAfterInstantiation() { NuspecFile file = new NuspecFile("test1.nuspec"); Expect.IsNotNullOrEmpty(file.Version.Value); Expect.AreEqual("1", file.Version.Major); Expect.AreEqual("0", file.Version.Minor); Expect.AreEqual("0", file.Version.Patch); Expect.IsNotNullOrEmpty(file.Title); Expect.IsNotNullOrEmpty(file.Id); Expect.IsNotNullOrEmpty(file.Authors); Expect.IsNotNullOrEmpty(file.Owners); Expect.IsNotNullOrEmpty(file.ReleaseNotes); Expect.IsFalse(file.RequireLicenseAcceptance); Expect.IsNotNullOrEmpty(file.Copyright); Expect.IsNotNullOrEmpty(file.Description); file.AddDependency("monkey", "1.0.0"); file.AddDependency("test", "[2]"); file.Version.IncrementPatch(); file.Save(); string content = file.Path.SafeReadFile(); Out(content, ConsoleColor.Cyan); File.Delete(file.Path); }
public override Task ExecuteAsync(CancellationToken cancellationToken) { var nuspecDirectoryName = Path.GetDirectoryName(NuspecFile.FileName); var packagesConfig = PackagesConfigFile.Load(nuspecDirectoryName); var csProj = CsProjFile.Load(Path.Combine(nuspecDirectoryName, $"{NuspecFile.Id}{CsProjFile.Extension}")); var packageDependencies = packagesConfig.Packages.Concat(csProj.PackageReferences).Select(package => new NuspecDependency { Id = package.Id, Version = package.Version }); var projectDependencies = csProj.ProjectReferences.Select(projectReferenceName => new NuspecDependency { Id = projectReferenceName, Version = Version }); NuspecFile.Dependencies = packageDependencies.Concat(projectDependencies); NuspecFile.Version = Version; NuspecFile.Save(); return(Task.CompletedTask); }
public static void SetBamInfo() { string nuspecRoot = GetNuspecRoot(); string bamInfoPath = (Arguments["baminfo.json"] ?? Prompt("Enter the path to the baminfo.json file")); string versionString = GetVersion(); string srcRoot = GetSourceRoot(); BamInfo info = bamInfoPath.FromJsonFile <BamInfo>(); int sinceMajor = info.MajorVersion; int sinceMinor = info.MinorVersion; int sincePatch = info.PatchVersion; Out("*** baminfo.json ***", ConsoleColor.Cyan); OutLine(info.PropertiesToString(), ConsoleColor.Cyan); OutLine("***", ConsoleColor.Cyan); OutLineFormat("Updating version from {0} to {1}", ConsoleColor.Yellow, info.VersionString, versionString); info.VersionString = versionString; info.ToJsonFile(bamInfoPath); GitReleaseNotes miscReleaseNotes = GitReleaseNotes.MiscSinceVersion(srcRoot, sinceMajor, sinceMinor, sincePatch); miscReleaseNotes.Summary = $"Version {versionString}"; OutLineFormat("Updating release notes:\r\n{0}", ConsoleColor.DarkYellow, info.ReleaseNotes); info.ReleaseNotes = miscReleaseNotes.Value; info.ToJsonFile(bamInfoPath); string rootReleaseNotes = Path.Combine(srcRoot, "RELEASENOTES"); miscReleaseNotes.Value.SafeWriteToFile(rootReleaseNotes, true); DirectoryInfo nuspecRootDir = new DirectoryInfo(nuspecRoot); FileInfo[] nuspecFiles = nuspecRootDir.GetFiles("*.nuspec", SearchOption.AllDirectories); foreach (FileInfo file in nuspecFiles) { NuspecFile nuspecFile = new NuspecFile(file.FullName); nuspecFile.Authors = info.Authors; nuspecFile.Owners = info.Owners; GitReleaseNotes releaseNotes = GitReleaseNotes.SinceVersion(nuspecFile.Id, srcRoot, sinceMajor, sinceMinor, sincePatch); if (!WriteReleaseNotes(srcRoot, releaseNotes, out string projectRoot)) { Warn("Unable to find project directory ({0}) to write release notes", projectRoot); } releaseNotes.Summary = $"Version {versionString}"; nuspecFile.ReleaseNotes = releaseNotes.Value; nuspecFile.Copyright = "Copyright © {0} {1}"._Format(info.Owners, DateTime.UtcNow.Year); nuspecFile.LicenseUrl = info.LicenseUrl; nuspecFile.ProjectUrl = info.ProjectUrl; string buildNumber = !string.IsNullOrEmpty(info.BuildNumber) ? "-{0}"._Format(info.BuildNumber) : ""; string patch = string.Format("{0}{1}", info.PatchVersion.ToString(), buildNumber); nuspecFile.Version.Major = info.MajorVersion.ToString(); nuspecFile.Version.Minor = info.MinorVersion.ToString(); nuspecFile.Version.Patch = patch; List <NugetPackageIdentifier> bamDependencies = new List <NugetPackageIdentifier>(); if (nuspecFile.Dependencies != null) { nuspecFile.Dependencies.Where(npi => npi.Id.StartsWith(typeof(Args).Namespace)).Each(npi => { bamDependencies.Add(new NugetPackageIdentifier(npi.Id, info.VersionString)); }); nuspecFile.Dependencies = bamDependencies.ToArray(); } nuspecFile.Save(); } }