public void CanPatchVersionOnWellFormedXml() { _patcher.Load(_projectXml); _patcher.PatchVersionField("1.0.0", "1.1.0-0"); var newXml = _patcher.ToXmlString(); Assert.NotEqual(_projectXml, newXml); Assert.Contains("<Version>1.1.0-0</Version>", newXml); }
public VersionInfo Execute(VersionCliArgs args) { if (!args.DryRun && args.DoVcs && !_vcsTool.IsVcsToolPresent()) { throw new OperationCanceledException( $"Unable to find the vcs tool {_vcsTool.ToolName()} in your path"); } if (!args.DryRun && args.DoVcs && !_vcsTool.IsRepositoryClean()) { throw new OperationCanceledException( "You currently have uncomitted changes in your repository, please commit these and try again"); } var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); var semVer = _bumper.Bump( SemVer.FromString(_fileParser.PackageVersion), args.VersionBump, args.SpecificVersionToApply, args.BuildMeta, args.PreReleasePrefix ); var versionString = semVer.ToSemVerVersionString(); if (!args.DryRun) // if we are not in dry run mode, then we should go ahead { _fileVersionPatcher.Load(csProjXml); _fileVersionPatcher.PatchVersionField( _fileParser.Version, versionString ); _fileVersionPatcher.Flush( _fileDetector.ResolvedCsProjFile ); if (args.DoVcs) { // Run git commands _vcsTool.Commit(_fileDetector.ResolvedCsProjFile, $"v{versionString}"); _vcsTool.Tag($"v{versionString}"); } } var theOutput = new VersionInfo { Product = new ProductOutputInfo { Name = ProductInfo.Name, Version = ProductInfo.Version }, OldVersion = _fileParser.PackageVersion, NewVersion = versionString, ProjectFile = _fileDetector.ResolvedCsProjFile, VersionStrategy = args.VersionBump.ToString().ToLowerInvariant() }; if (args.OutputFormat == OutputFormat.Json) { WriteJsonToStdout(theOutput); } else { Console.WriteLine($"Bumped {_fileDetector.ResolvedCsProjFile} to version {versionString}"); } return(theOutput); }