Skip to content

Commit 2ff3367

Browse files
committed
Update to .NET 9. Changed the Update Options schema
1 parent 0ca78cd commit 2ff3367

File tree

15 files changed

+138
-184
lines changed

15 files changed

+138
-184
lines changed

.github/workflows/build-publish-nuget.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
build:
2020
runs-on: ubuntu-latest
2121
env:
22-
DOTNET_VERSION: 8.0.x
22+
DOTNET_VERSION: 9.0.x
2323
SRC_DIRECTORY_PATH_LIB: ${{ github.workspace }}/src
2424
PROJECT_NAME_LIB: PublicInterfaceGenerator
2525
NUGET_VERSION: ${{ github.event.inputs.nuget_version_override || '1.0.0-preview' }}.${{ github.run_number }}

README.md

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ It would be great to get this to work for all kinds of languages/frameworks some
66

77
## What Updates Can Be Done
88

9-
- Update .NET `*.csproj` files to use a specified C# Language Version
10-
- Update .NET `*.csproj` files to use a specified .NET SDK Version (AKA TargetFramework element)
9+
- Update `*.csproj` files to use a specified C# Language Version
10+
- Update `*.csproj` files to use a specified .NET SDK Version (AKA TargetFramework element)
1111
- Enable/Disable .NET Analyzers in all `*.csproj` files
1212
- Run `dotnet format` command on all `*.csproj` files
1313
- Update all NuGet packages in all *`.csproj` files to the latest version
1414
- Add Nuget auditing properties to all `*.csproj` files
15-
- Update all NPM packages in all package.json files to the latest version
15+
- Update all NPM packages in all `package.json` files to the latest version
16+
- Search all included files for a regex pattern
1617

1718
## How to Use It
1819

@@ -38,9 +39,11 @@ Remember, the purpose of this is to update code and dependencies. It is assumed,
3839
- `-h|--help`
3940
- Outputs CLI help
4041

41-
## Options File
42+
## Update Options File
4243

43-
This is a config file used by the app to determine what updates to run. It is composed of different objects which enable certain update features. Setting an object means that feature will run. Omitting it from the file will disable that update feature.
44+
This is a config file used by the app to determine what updates to run. It is composed of different objects which enable certain update features. Setting an object means that feature will run. Omitting it from the file will disable that update feature.
45+
46+
Below is a list of the required and optional propeties for the Update Options JSON. There is also a JSON Schema for this file at the root of this repository titled `UpdateOptionsSchema.json` which you can use to validate before running, if it helps.
4447

4548
- UpdatePathOptions
4649
- Required
@@ -89,24 +92,28 @@ This is a config file used by the app to determine what updates to run. It is co
8992
- Required Properties:
9093
- RunDotnetFormat
9194
- Boolean. True to run the `dotnet format` command
92-
- NugetAuditOptions
93-
- Optional
94-
- Settings to use for configuring Nuget Audit settings in csproj files. You can read more at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
95-
- Required Properties:
96-
- NuGetAudit
97-
- Boolean. What value to set for the `NuGetAudit` property in the csproj file.
98-
- AuditMode
99-
- String. What value to set for the `NuGetAuditMode` property in the csproj file. Valid values are `direct` and `all`.
100-
- AuditLevel
101-
- String. What value to set for the `NuGetAuditLevel` property in the csproj file. Valid values are: `low`, `moderate`, `high`, and `critical`
102-
- NuGetUpdateOptions
95+
- NugetOptions
10396
- Optional
104-
- Settings to use for updating NuGet packages in csproj files
105-
- Required Properties:
106-
- UpdateTopLevelNugetsInCsProj
107-
- Boolean. True to updates all referenced nugets to the latest version. These are the references in the csproj files.
108-
- UpdateTopLevelNugetsNotInCsProj
109-
- Boolean. True to updates all indirect nugets to the latest version. These are the nugets that are referenced automatically based on SDK chosen or something like that.
97+
- Options for updating Nuget packages in csproj files
98+
- Properties:
99+
- AuditOptions
100+
- Optional
101+
- Settings to use for configuring Nuget Audit settings in csproj files. You can read more at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
102+
- Required Properties:
103+
- NuGetAudit
104+
- Boolean. What value to set for the `NuGetAudit` property in the csproj file.
105+
- AuditMode
106+
- String. What value to set for the `NuGetAuditMode` property in the csproj file. Valid values are `direct` and `all`.
107+
- AuditLevel
108+
- String. What value to set for the `NuGetAuditLevel` property in the csproj file. Valid values are: `low`, `moderate`, `high`, and `critical`
109+
- UpdateOptions
110+
- Optional
111+
- Settings to use for updating NuGet packages in csproj files
112+
- Required Properties:
113+
- UpdateTopLevelNugetsInCsProj
114+
- Boolean. True to updates all referenced nugets to the latest version. These are the references in the csproj files.
115+
- UpdateTopLevelNugetsNotInCsProj
116+
- Boolean. True to updates all indirect nugets to the latest version. These are the nugets that are referenced automatically based on SDK chosen or something like that.
110117
- NpmOptions
111118
- Optional
112119
- Options for updating Npm packages. If this is not set, NPM packages will not be updated
@@ -120,7 +127,7 @@ This is a config file used by the app to determine what updates to run. It is co
120127
- String. Npm command to "compile" the npm directory. The CLI command that will be run is: `npm run {{NpmBuildCommand}}`
121128
- RegexSearchOptions
122129
- Optional
123-
- Regex to search for specific string. Handy for finding things you need to manually update, that this tool can't easily do. For example, setting the correct version of .NET in a YAML file for a CI/CD Pipeline
130+
- Regex to search for specific string. Handy for finding things you need to manually update, that this tool can't easily do. For example, use this to search for the hard coded .NET version in a YAML file for a CI/CD Pipeline so you know where to manually update it
124131
- Required Properties:
125132
- Searches:
126133
- Collection of searches to make in all files that are not ignored
@@ -135,49 +142,52 @@ This is a config file used by the app to determine what updates to run. It is co
135142

136143
```json
137144
{
138-
{
139-
"UpdatePathOptions": {
140-
"RootDirectory": "D:\\GitHub\\ProgrammerAL\\ProgrammerAlSite",
141-
"IgnorePatterns": [
145+
"updatePathOptions": {
146+
"rootDirectory": "./",
147+
"ignorePatterns": [
142148
"/samples/",
143149
"\\samples\\"
144150
]
145151
},
146-
"LoggingOptions": {
147-
"LogLevel": "Verbose",
148-
"OutputFile": "./code-updater-output.txt"
152+
"loggingOptions": {
153+
"logLevel": "Verbose",
154+
"outputFile": "./code-updater-output.txt"
149155
},
150-
"CSharpOptions": {
151-
"CsProjVersioningOptions": {
152-
"TreatWarningsAsErrors": true,
153-
"TargetFramework": "net8.0",
154-
"LangVersion": "latest"
155-
},
156-
"CsProjDotNetAnalyzerOptions": {
157-
"EnableNetAnalyzers": true,
158-
"EnforceCodeStyleInBuild": true
156+
"cSharpOptions": {
157+
"csProjVersioningOptions": {
158+
"treatWarningsAsErrors": true,
159+
"targetFramework": "net8.0",
160+
"langVersion": "latest"
159161
},
160-
"CSharpStyleOptions": {
161-
"RunDotnetFormat": true
162+
"csProjDotNetAnalyzerOptions": {
163+
"enableNetAnalyzers": true,
164+
"enforceCodeStyleInBuild": true
162165
},
163-
"NugetAuditOptions": {
164-
"NuGetAudit": true,
165-
"AuditMode": "all",
166-
"AuditLevel": "low"
166+
"cSharpStyleOptions": {
167+
"runDotnetFormat": true
167168
},
168-
"NuGetUpdateOptions": {
169-
"UpdateTopLevelNugetsInCsProj": true,
170-
"UpdateTopLevelNugetsNotInCsProj": true
169+
"nugetOptions": {
170+
"auditOptions": {
171+
"nuGetAudit": true,
172+
"auditMode": "all",
173+
"auditLevel": "low"
174+
},
175+
"updateOptions": {
176+
"updateTopLevelNugetsInCsProj": true,
177+
"updateTopLevelNugetsNotInCsProj": true
178+
}
171179
}
172180
},
173-
"NpmOptions": {
174-
"NpmBuildCommand": "publish"
181+
"npmOptions": {
182+
"compileOptions": {
183+
"buildCommand": "publish"
184+
}
175185
},
176-
"RegexSearchOptions": {
177-
"Searches": [
186+
"regexSearchOptions": {
187+
"searches": [
178188
{
179-
"SearchRegex": "[0-9]{1,2}\\..+\\.x",
180-
"Description": "YAML Dotnet Version"
189+
"searchRegex": "[0-9]{1,2}\\..+\\.x",
190+
"description": "YAML Dotnet Version"
181191
}
182192
]
183193
}

build/Build.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
<LangVersion>latest</LangVersion>
@@ -10,9 +10,9 @@
1010
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageReference Include="Cake.Frosting" Version="4.2.0" />
14-
<PackageReference Include="NuGet.Packaging" Version="6.11.1" />
15-
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
13+
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
14+
<PackageReference Include="NuGet.Packaging" Version="6.12.1" />
15+
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
1616
</ItemGroup>
1717
<PropertyGroup>
1818
<NuGetAudit>true</NuGetAudit>
Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
{
2-
"UpdatePathOptions": {
3-
"RootDirectory": "../",
4-
"IgnorePatterns": [
2+
"updatePathOptions": {
3+
"rootDirectory": "./",
4+
"ignorePatterns": [
55
"/samples/",
66
"\\samples\\"
77
]
88
},
9-
"LoggingOptions": {
10-
"LogLevel": "Verbose",
11-
"OutputFile": "./code-updater-output.txt"
9+
"loggingOptions": {
10+
"logLevel": "Verbose",
11+
"outputFile": "./code-updater-output.txt"
1212
},
13-
"CSharpOptions": {
14-
"CsProjVersioningOptions": {
15-
"TreatWarningsAsErrors": true,
16-
"TargetFramework": "net8.0",
17-
"LangVersion": "latest"
13+
"cSharpOptions": {
14+
"csProjVersioningOptions": {
15+
"treatWarningsAsErrors": true,
16+
"targetFramework": "net8.0",
17+
"langVersion": "latest"
1818
},
19-
"CsProjDotNetAnalyzerOptions": {
20-
"EnableNetAnalyzers": true,
21-
"EnforceCodeStyleInBuild": true
19+
"csProjDotNetAnalyzerOptions": {
20+
"enableNetAnalyzers": true,
21+
"enforceCodeStyleInBuild": true
2222
},
23-
"CSharpStyleOptions": {
24-
"RunDotnetFormat": false
23+
"cSharpStyleOptions": {
24+
"runDotnetFormat": true
2525
},
26-
"NugetAuditOptions": {
27-
"NuGetAudit": true,
28-
"AuditMode": "all",
29-
"AuditLevel": "low"
30-
},
31-
"NuGetUpdateOptions": {
32-
"UpdateTopLevelNugetsInCsProj": true,
33-
"UpdateTopLevelNugetsNotInCsProj": false
26+
"nugetOptions": {
27+
"auditOptions": {
28+
"nuGetAudit": true,
29+
"auditMode": "all",
30+
"auditLevel": "low"
31+
},
32+
"updateOptions": {
33+
"updateTopLevelNugetsInCsProj": true,
34+
"updateTopLevelNugetsNotInCsProj": true
35+
}
3436
}
3537
},
36-
"NpmOptions": {
37-
"NpmCompileOptions":{
38-
"BuildCommand": "publish"
38+
"npmOptions": {
39+
"compileOptions": {
40+
"buildCommand": "publish"
3941
}
42+
},
43+
"regexSearchOptions": {
44+
"searches": [
45+
{
46+
"searchRegex": "[0-9]{1,2}\\..+\\.x",
47+
"description": "YAML Dotnet Version"
48+
}
49+
]
4050
}
4151
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
$configPath = "$PSScriptRoot/code-updater-config.json"
22

33
& "code-updater" --options "$configPath"
4-
5-
Read-Host "Press enter to exit..."

src/CodeUpdater/CodeUpdater/CodeUpdater.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

src/CodeUpdater/CodeUpdater/CompileRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public async ValueTask<CompileResults> CompileProjectsAsync(UpdateWork updateWor
2323

2424
private async ValueTask<CompileNpmDirectoryResults> BuildAllNpmDirectoriesAsync(UpdateWork updateWork, UpdateOptions updateOptions)
2525
{
26-
var npmBuildCommand = updateOptions.NpmOptions?.NpmCompileOptions?.BuildCommand;
26+
var npmBuildCommand = updateOptions.NpmOptions?.CompileOptions?.BuildCommand;
2727
if (!string.IsNullOrWhiteSpace(npmBuildCommand))
2828
{
29-
Logger.Information("Np NpmOptions config set, meaning no NPM Packages Updated, meaning nothing to compile");
29+
Logger.Information("No NpmOptions config set, meaning no NPM Packages Updated, meaning nothing to compile");
3030
return new CompileNpmDirectoryResults(ImmutableArray<CompileNpmDirectoryResult>.Empty);
3131
}
3232

src/CodeUpdater/CodeUpdater/Options/UpdateOptions.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class UpdateOptions
2222
public NpmOptions? NpmOptions { get; set; }
2323

2424
/// <summary>
25-
/// Regex to search for specific string. Handy for finding things you need to manually update, that this tool can't easily do. For example, setting the correct version of .NET in a YAML file for a CI/CD Pipeline
25+
/// Regex to search for specific string. Handy for finding things you need to manually update, that this tool can't easily do. For example, use this to search for the hard coded .NET version in a YAML file for a CI/CD Pipeline so you know where to manually update it
2626
/// </summary>
2727
public RegexSearchOptions? RegexSearchOptions { get; set; }
2828

@@ -56,7 +56,7 @@ public class NpmOptions
5656
/// <summary>
5757
/// Options for compiling Npm packages after updates. Note if this is not set, but the parent NpmOptions is set, NPM Packages will be updated but not tested with a compile.
5858
/// </summary>
59-
public NpmCompileOptions? NpmCompileOptions { get; set; }
59+
public NpmCompileOptions? CompileOptions { get; set; }
6060
}
6161

6262
public class NpmCompileOptions
@@ -86,15 +86,9 @@ public class CSharpOptions
8686
public CSharpStyleOptions? CSharpStyleOptions { get; set; }
8787

8888
/// <summary>
89-
/// Settings to use for configuring Nuget Audit settings in csproj files.
90-
/// You can read more at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
89+
/// Options for updating Nuget packages in csproj files
9190
/// </summary>
92-
public NugetAuditOptions? NugetAuditOptions { get; set; }
93-
94-
/// <summary>
95-
/// Settings to use for updating NuGet packages in csproj files
96-
/// </summary>
97-
public NuGetUpdateOptions? NuGetUpdateOptions { get; set; }
91+
public NugetOptions? NugetOptions { get; set; }
9892
}
9993

10094
public class CsProjVersioningOptions
@@ -142,6 +136,20 @@ public class CSharpStyleOptions
142136
public required bool RunDotnetFormat { get; set; }
143137
}
144138

139+
public class NugetOptions
140+
{
141+
/// <summary>
142+
/// Settings to use for configuring Nuget Audit settings in csproj files.
143+
/// You can read more at https://learn.microsoft.com/en-us/nuget/concepts/auditing-packages#configuring-nuget-audit
144+
/// </summary>
145+
public NugetAuditOptions? AuditOptions { get; set; }
146+
147+
/// <summary>
148+
/// Settings to use for updating NuGet packages in csproj files
149+
/// </summary>
150+
public NuGetUpdateOptions? UpdateOptions { get; set; }
151+
}
152+
145153
public class NugetAuditOptions
146154
{
147155
/// <summary>

src/CodeUpdater/CodeUpdater/Program.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ static ILogger SetupLogger(UpdateOptions updateOptions)
8989

9090
static async Task<UpdateOptions> LoadUpdateOptionsAsync(string configFilePath)
9191
{
92+
var jsonSerializationOptions = new JsonSerializerOptions
93+
{
94+
PropertyNameCaseInsensitive = true,
95+
AllowTrailingCommas = true,
96+
};
97+
9298
if (!File.Exists(configFilePath))
9399
{
94100
throw new Exception($"Config file does not exist at path: {configFilePath}");
@@ -100,11 +106,7 @@ static async Task<UpdateOptions> LoadUpdateOptionsAsync(string configFilePath)
100106
throw new Exception($"Config file is empty at path: {configFilePath}");
101107
}
102108

103-
var updateOptions = JsonSerializer.Deserialize<UpdateOptions>(updateOptionJson, new JsonSerializerOptions
104-
{
105-
PropertyNameCaseInsensitive = true,
106-
AllowTrailingCommas = true,
107-
});
109+
var updateOptions = JsonSerializer.Deserialize<UpdateOptions>(updateOptionJson, jsonSerializationOptions);
108110

109111
if (updateOptions is null)
110112
{

0 commit comments

Comments
 (0)