Skip to content

Commit b550293

Browse files
authored
dependencies: migrate from json.net to system.text.json (#1274)
# Overview Migrate GCM from JSON.NET to `System.Text.Json`. The first commit updates to .NET 7.0 to take advantage of certain features like `JsonRequired`. The second updates `Microsoft.Identity.Client` so that the workaround for [this issue](AzureAD/microsoft-authentication-library-for-dotnet#4108 ) is no longer necessary. The third updates the current global Json.NET dependency to `System.Text.Json` and ensures it is only used for .NET Framework. The fourth adds a custom converter to handle Bitbucket's use of the non-standard 'scopes' property to provide token endpoint results. The fifth through ninth commits update `Trace2Message`, the Bitbucket REST API, the GitHub REST API, the Azure DevOps API tests, and OAuth-specific code to use `System.Text.Json` instead of Json.NET for JSON serialization/deserialization. # Performance comparison Comparison runs were done using [`dotnet-trace`](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace) with the command `printf "protocol=https\nhost=github.com" | git-credential-manager get`. The machine used was a Mac with a 2.4 GHz 8-Core Intel Core i9 processor running Ventura 13.4. Times are in milliseconds. ## Individual Run Times | **Newtonsoft.json** | **System.Text.Json** | |---------------------|----------------------| | 364.08 | 304.92 | | 366.11 | 305.23 | | 377.31 | 313.09 | | 381.3 | 313.51 | | 373.25 | 297.71 | | 373.98 | 312.78 | | 370.84 | 317.86 | | 368.25 | 311.78 | | 369.79 | 307.69 | ## Run Summary | | **Newtonsoft.json** | **System.Text.Json** | |-------------|---------------------|----------------------| | **Average** | 371.66 | 309.40 | | **Median** | 370.84 | 311.78 | ## Analysis Per the above, the transition to `System.Text.Json` and .NET 7.0 decreased end-to-end execution times by about 17% on average.
2 parents d66558b + 2e153ce commit b550293

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+430
-292
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/out/shared/Git-Credential-Manager/bin/Debug/net6.0/git-credential-manager.dll",
13+
"program": "${workspaceFolder}/out/shared/Git-Credential-Manager/bin/Debug/net7.0/git-credential-manager.dll",
1414
"args": ["get"],
1515
"cwd": "${workspaceFolder}/out/shared/Git-Credential-Manager",
1616
"console": "integratedTerminal",
@@ -22,7 +22,7 @@
2222
"request": "launch",
2323
"preLaunchTask": "build",
2424
// If you have changed target frameworks, make sure to update the program path.
25-
"program": "${workspaceFolder}/out/shared/Git-Credential-Manager/bin/Debug/net6.0/git-credential-manager.dll",
25+
"program": "${workspaceFolder}/out/shared/Git-Credential-Manager/bin/Debug/net7.0/git-credential-manager.dll",
2626
"args": ["store"],
2727
"cwd": "${workspaceFolder}/out/shared/Git-Credential-Manager",
2828
"console": "integratedTerminal",

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"type": "shell",
5757
"group": "test",
5858
"args": [
59-
"~/.nuget/packages/reportgenerator/*/*/net6.0/ReportGenerator.dll",
59+
"~/.nuget/packages/reportgenerator/*/*/net7.0/ReportGenerator.dll",
6060
"-reports:${workspaceFolder}/**/TestResults/**/coverage.cobertura.xml",
6161
"-targetdir:${workspaceFolder}/out/code-coverage"
6262
],
@@ -71,7 +71,7 @@
7171
"type": "shell",
7272
"group": "test",
7373
"args": [
74-
"${env:USERROFILE}/.nuget/packages/reportgenerator/*/*/net6.0/ReportGenerator.dll",
74+
"${env:USERROFILE}/.nuget/packages/reportgenerator/*/*/net7.0/ReportGenerator.dll",
7575
"-reports:${workspaceFolder}/**/TestResults/**/coverage.cobertura.xml",
7676
"-targetdir:${workspaceFolder}/out/code-coverage"
7777
],

Directory.Build.props

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
<GenerateWindowsAppManifest Condition="'$(GenerateWindowsAppManifest)' == '' AND '$(OSPlatform)' == 'windows' AND '$(_IsExeProject)' == 'true'">true</GenerateWindowsAppManifest>
2727
</PropertyGroup>
2828

29-
<ItemGroup>
30-
<!-- Workaround https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4108 -->
31-
<PackageReference Include="Newtonsoft.Json">
32-
<Version>13.0.1</Version>
29+
<ItemGroup Condition = "'$(TargetFramework)' == 'net472'">
30+
<PackageReference Include="System.Text.Json">
31+
<Version>7.0.2</Version>
3332
</PackageReference>
3433
</ItemGroup>
3534

build/GCM.MSBuild.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

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<IncludeBuildOutput>false</IncludeBuildOutput>
66
</PropertyGroup>
77

docs/development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ HTML reports can be generated using ReportGenerator, this should be installed
209209
during the build process, from the command line:
210210

211211
```shell
212-
dotnet ~/.nuget/packages/reportgenerator/*/*/net6.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage
212+
dotnet ~/.nuget/packages/reportgenerator/*/*/net7.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage
213213
```
214214

215215
or
216216

217217
```shell
218-
dotnet {$env:USERPROFILE}/.nuget/packages/reportgenerator/*/*/net6.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage
218+
dotnet {$env:USERPROFILE}/.nuget/packages/reportgenerator/*/*/net7.0/ReportGenerator.dll -reports:./**/TestResults/**/coverage.cobertura.xml -targetdir:./out/code-coverage
219219
```
220220

221221
Or via VSCode Terminal/Run Task:

src/linux/Packaging.Linux/Packaging.Linux.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
44

55
<PropertyGroup>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFramework>net7.0</TargetFramework>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
</PropertyGroup>
99

src/linux/Packaging.Linux/layout.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ GCM_SRC="$SRC/shared/Git-Credential-Manager"
3838
PROJ_OUT="$OUT/linux/Packaging.Linux"
3939

4040
# Build parameters
41-
FRAMEWORK=net6.0
41+
FRAMEWORK=net7.0
4242
RUNTIME=linux-x64
4343

4444
# Perform pre-execution checks

src/osx/Installer.Mac/Installer.Mac.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
44

55
<PropertyGroup>
6-
<TargetFramework>net6.0</TargetFramework>
6+
<TargetFramework>net7.0</TargetFramework>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
</PropertyGroup>
99

src/osx/Installer.Mac/layout.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ GCM_SRC="$SRC/shared/Git-Credential-Manager"
2424
GCM_UI_SRC="$SRC/shared/Git-Credential-Manager.UI.Avalonia"
2525

2626
# Build parameters
27-
FRAMEWORK=net6.0
27+
FRAMEWORK=net7.0
2828

2929
# Parse script arguments
3030
for i in "$@"

src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.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

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<IsTestProject>true</IsTestProject>
77
<LangVersion>latest</LangVersion>

0 commit comments

Comments
 (0)