Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convert VMR tasks from Newtonsoft.Json to System.Text.Json #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 22, 2025

Summary

This PR migrates all .cs files in the VMR outside of /src from Newtonsoft.Json to System.Text.Json. The changes were made to achieve better compatibility with the modern .NET ecosystem and reduce dependencies on third-party libraries when the standard library provides equivalent functionality.

Changes

  • Updated Microsoft.DotNet.UnifiedBuild.Tasks.csproj to reference System.Text.Json instead of Newtonsoft.Json
  • Converted three files to use System.Text.Json:
    • UpdateJson.cs
    • WriteUsageBurndownData.cs
    • WritePackageUsageData.cs

Implementation Details

  • Replaced JObject/JToken with JsonDocument/JsonElement/JsonNode
  • Migrated from JsonTextReader to JsonDocument.Parse() methods
  • Updated navigation patterns from SelectToken to TryGetProperty and EnumerateObject
  • Properly implemented IDisposable pattern with using statements for JsonDocument
  • Modified property access patterns to work with System.Text.Json's immutable JsonElement

Testing

Verified that all Newtonsoft.Json references were removed from files outside the /src directory.

Fixes #714.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkgs.dev.azure.com
    • Triggering command: dotnet build Microsoft.DotNet.UnifiedBuild.Tasks/Microsoft.DotNet.UnifiedBuild.Tasks.csproj -c Release (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits May 22, 2025 09:32
…t.Json

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Convert VMR tasks use of Newtonsoft.Json to System.Text.Json Convert VMR tasks from Newtonsoft.Json to System.Text.Json May 22, 2025
@Copilot Copilot AI requested a review from ViktorHofer May 22, 2025 09:39
Copilot finished work on behalf of ViktorHofer May 22, 2025 09:39
@ViktorHofer
Copy link
Member

@copilot remove the System.Text.Json package reference from eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/Microsoft.DotNet.UnifiedBuild.Tasks.csproj. That one isn't necessary when targeting .NETCoreApp.

Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 22, 2025

@copilot remove the System.Text.Json package reference from eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/Microsoft.DotNet.UnifiedBuild.Tasks.csproj. That one isn't necessary when targeting .N...

I've removed the System.Text.Json package reference from Microsoft.DotNet.UnifiedBuild.Tasks.csproj as requested since it's already included in .NETCoreApp. See commit 718e8c1.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkgs.dev.azure.com
    • Triggering command: dotnet build eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/Microsoft.DotNet.UnifiedBuild.Tasks.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of ViktorHofer May 22, 2025 10:12
@MichaelSimons
Copy link
Member

Does this remove the last references of the Directory.Pacakges.props and Versions.props entries for Newtonsoft?

Copy link
Contributor Author

Copilot AI commented May 22, 2025

Does this remove the last references of the Directory.Pacakges.props and Versions.props entries for Newtonsoft?

No, this doesn't remove the last references to Newtonsoft.Json in Directory.Packages.props and Versions.props. The test projects (Microsoft.DotNet.Tests.csproj and Microsoft.DotNet.SourceBuild.Tests.csproj) still reference Newtonsoft.Json. Additionally, the issue (#714) specifically requested to convert .cs files outside of /src, meaning code under /src may still use Newtonsoft.Json.

Copilot finished work on behalf of MichaelSimons May 22, 2025 13:25
@akoeplinger
Copy link
Member

@copilot there's an error in the WritePackageUsageData task in line 244, the build shows:

/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018: The "WritePackageUsageData" task failed unexpectedly.
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018: System.AggregateException->Microsoft.Build.Framework.BuildException.GenericBuildTransferredException: One or more errors occurred. (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.) (The requested operation requires an element of type 'String', but the target element has type 'True'.)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:  ---> System.InvalidOperationException->Microsoft.Build.Framework.BuildException.GenericBuildTransferredException: The requested operation requires an element of type 'String', but the target element has type 'True'.
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Text.Json.JsonDocument.GetString(Int32 index, JsonTokenType expectedType)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WritePackageUsageData.<>c__DisplayClass48_0.<Execute>b__2(String assetFile) in /_/eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/UsageReport/WritePackageUsageData.cs:line 244
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018: --- End of stack trace from previous location ---
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.TaskReplicator.Replica.Execute()
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    --- End of inner exception stack trace ---
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018: --- End of stack trace from previous location ---
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WritePackageUsageData.Execute() in /_/eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/UsageReport/WritePackageUsageData.cs:line 180
/__w/1/s/eng/finish-source-only.proj(67,5): error MSB4018:    at Microsoft.Build.CommandLine.OutOfProcTaskAppDomainWrapperBase.InstantiateAndExecuteTask(IBuildEngine oopTaskHostNode, LoadedType taskType, String taskName, String taskLocation, String taskFile, Int32 taskLine, Int32 taskColumn, IDictionary`2 taskParams)

Co-authored-by: akoeplinger <1376924+akoeplinger@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 22, 2025

@copilot there's an error in the WritePackageUsageData task in line 244, the build shows:

...

Fixed the error in WritePackageUsageData.cs by changing GetString() to GetBoolean() for the autoReferenced property in line 244. In System.Text.Json, boolean values need to be explicitly read with the correct type, unlike Newtonsoft.Json where they could be implicitly converted to strings. See commit 242c590.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkgs.dev.azure.com
    • Triggering command: dotnet build eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/Microsoft.DotNet.UnifiedBuild.Tasks.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of akoeplinger May 22, 2025 18:51
Comment on lines +247 to +251
if (versionStr != null)
{
var version = VersionRange.Parse(versionStr);
directDependencies.Add((dep.Name, target, version, autoReferenced));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if branch didn't exist previously. Direct dependencies were always added, regardless of the version string being null. Not sure if it matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert VMR tasks use of Newtonsoft.Json to System.Text.Json
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.