Skip to content

Commit 45cedac

Browse files
committed
VersionBump : v5.0.0-preview.8
1 parent 1485064 commit 45cedac

File tree

6 files changed

+91
-28
lines changed

6 files changed

+91
-28
lines changed

src/CodeOfChaos.CliArgsParser.Contracts/CodeOfChaos.CliArgsParser.Contracts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Main package name -->
1010
<PackageId>CodeOfChaos.CliArgsParser.Contracts</PackageId>
11-
<Version>5.0.0-preview.7</Version>
11+
<Version>5.0.0-preview.8</Version>
1212
<Authors>Anna Sas</Authors>
1313
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1414
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>

src/CodeOfChaos.CliArgsParser.Generators/CodeOfChaos.CliArgsParser.Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<!-- Main package name -->
1313
<PackageId>CodeOfChaos.CliArgsParser.Generators</PackageId>
14-
<Version>5.0.0-preview.7</Version>
14+
<Version>5.0.0-preview.8</Version>
1515
<Authors>Anna Sas</Authors>
1616
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1717
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>

src/CodeOfChaos.CliArgsParser.Library/CodeOfChaos.CliArgsParser.Library.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- Main package name -->
1010
<PackageId>CodeOfChaos.CliArgsParser.Library</PackageId>
11-
<Version>5.0.0-preview.7</Version>
11+
<Version>5.0.0-preview.8</Version>
1212
<Authors>Anna Sas</Authors>
1313
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1414
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>

src/CodeOfChaos.CliArgsParser.Library/Commands/VersionBump/VersionBumpCommand.cs

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,39 +82,92 @@ public async ValueTask ExecuteAsync(VersionBumpParameters parameters, Cancellati
8282
VersionSection sectionToBump = args.Section;
8383
SemanticVersionDto? versionDto = null;
8484

85+
// Process csproj files
8586
await foreach (XDocument document in CsProjHelpers.GetProjectFiles(projectFiles)) {
86-
XElement? versionElement = document
87-
.Descendants("PropertyGroup")
88-
.Elements("Version")
89-
.FirstOrDefault();
90-
91-
// Only needed for logging, so setting to "UNKNOWN" is okay
92-
string projectName = document
93-
.Descendants("PropertyGroup")
94-
.Elements("PackageId")
95-
.FirstOrDefault()?
96-
.Value ?? "UNKNOWN";
97-
98-
if (versionElement == null) {
99-
ErrorMessages.Add($"File {projectName} did not contain a version element");
100-
continue;
87+
string projectName = GetProjectNameFromCsproj(document);
88+
89+
SemanticVersionDto? result = ProcessCsprojFile(document, projectName, versionDto, sectionToBump);
90+
if (result is not null) {
91+
versionDto = result;
10192
}
93+
}
10294

103-
if (versionDto is null) {
104-
if (!SemanticVersionDto.TryParse(versionElement.Value, out SemanticVersionDto? dto)) {
105-
ErrorMessages.Add($"File {projectName} contained an invalid version element: {versionElement.Value}");
106-
continue;
107-
}
95+
// Process nuspec files
96+
await ProcessNuspecFiles(projectFiles, versionDto);
97+
98+
return versionDto;
99+
}
108100

109-
dto.BumpVersion(sectionToBump);
101+
private static SemanticVersionDto? ProcessCsprojFile(XDocument document, string projectName, SemanticVersionDto? currentVersion, VersionSection sectionToBump) {
102+
XElement? versionElement = document
103+
.Descendants("PropertyGroup")
104+
.Elements("Version")
105+
.FirstOrDefault();
110106

111-
versionDto = dto;
107+
if (versionElement == null) {
108+
ErrorMessages.Add($"File {projectName} did not contain a version element");
109+
return null;
110+
}
111+
112+
SemanticVersionDto? versionDto = currentVersion;
113+
114+
if (versionDto is null) {
115+
if (!SemanticVersionDto.TryParse(versionElement.Value, out SemanticVersionDto? dto)) {
116+
ErrorMessages.Add($"File {projectName} contained an invalid version element: {versionElement.Value}");
117+
return null;
112118
}
113119

114-
versionElement.Value = versionDto.ToString();
115-
Console.WriteLine(ConsoleTextStore.UpdatedVersion(projectName, versionElement.Value));
120+
dto.BumpVersion(sectionToBump);
121+
versionDto = dto;
116122
}
117123

124+
versionElement.Value = versionDto.ToString();
125+
Console.WriteLine(ConsoleTextStore.UpdatedVersion(projectName, versionElement.Value));
118126
return versionDto;
119127
}
128+
129+
private static async Task ProcessNuspecFiles(string[] projectFiles, SemanticVersionDto? versionDto) {
130+
if (versionDto == null) return;
131+
132+
foreach (string projectFile in projectFiles) {
133+
string nuspecFile = Path.ChangeExtension(projectFile, ".nuspec");
134+
if (!File.Exists(nuspecFile)) continue;
135+
136+
try {
137+
XDocument nuspecDocument;
138+
await using (var stream = new FileStream(nuspecFile, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) {
139+
nuspecDocument = await XDocument.LoadAsync(stream, LoadOptions.PreserveWhitespace, CancellationToken.None);
140+
}
141+
142+
XNamespace ns = nuspecDocument.Root?.GetDefaultNamespace() ?? XNamespace.None;
143+
XElement? versionElement = nuspecDocument
144+
.Descendants(ns + "metadata")
145+
.Elements(ns + "version")
146+
.FirstOrDefault();
147+
148+
if (versionElement != null) {
149+
versionElement.Value = versionDto.ToString();
150+
151+
// Save the nuspec file
152+
await using var stream = new FileStream(nuspecFile, FileMode.Create, FileAccess.Write);
153+
await nuspecDocument.SaveAsync(stream, SaveOptions.None, CancellationToken.None);
154+
155+
string nuspecName = Path.GetFileNameWithoutExtension(nuspecFile);
156+
Console.WriteLine(ConsoleTextStore.UpdatedVersion(nuspecName, versionElement.Value));
157+
}
158+
}
159+
catch (Exception ex) {
160+
ErrorMessages.Add($"Failed to process nuspec file {nuspecFile}: {ex.Message}");
161+
}
162+
}
163+
}
164+
165+
private static string GetProjectNameFromCsproj(XDocument document) {
166+
return document
167+
.Descendants("PropertyGroup")
168+
.Elements("PackageId")
169+
.FirstOrDefault()?
170+
.Value ?? "UNKNOWN";
171+
}
172+
120173
}

src/CodeOfChaos.CliArgsParser/CodeOfChaos.CliArgsParser.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
<!-- Main package name -->
99
<PackageId>CodeOfChaos.CliArgsParser</PackageId>
10-
<Version>5.0.0-preview.7</Version>
10+
<NuSpecFile>CodeOfChaos.CliArgsParser.nuspec</NuSpecFile>
11+
<Version>5.0.0-preview.8</Version>
1112
<Authors>Anna Sas</Authors>
1213
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1314
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>CodeOfChaos.CliArgsParser</id>
5+
<version>5.0.0-preview.8</version>
6+
<authors>Anna Sas</authors>
7+
<description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</description>
8+
</metadata>
9+
</package>

0 commit comments

Comments
 (0)