Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<!-- https://github.com/dotnet/sdk/issues/14801 -->
<AssemblyVersion Condition="'$(TargetFramework)'=='net472'">5.0.100.0</AssemblyVersion>

<UseSystemTextJson Condition="'$(TargetFramework)'!='netstandard2.0' And '$(TargetFramework)'!='net472'">True</UseSystemTextJson>
<DefineConstants Condition="'$(UseSystemTextJson)'=='True'">$(DefineConstants);USE_SYSTEM_TEXT_JSON</DefineConstants>

<!--https://github.com/NuGet/Home/issues/3891#issuecomment-377319939-->
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
Expand Down Expand Up @@ -63,8 +60,4 @@
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="System.Text.Json" VersionOverride="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Condition="'$(UseSystemTextJson)'!='True'"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

<Nullable>Enable</Nullable>

<UseSystemTextJson Condition="'$(TargetFramework)'!='netstandard2.0'">True</UseSystemTextJson>
<DefineConstants Condition="'$(UseSystemTextJson)'=='True'">$(DefineConstants);USE_SYSTEM_TEXT_JSON</DefineConstants>

<!-- Netfx version of the resolver builds against the lowest version of System.Text.Json that's guaranteed to be shipped with MSBuild in VS -->
<SystemTextJsonVersionOverride>8.0.0</SystemTextJsonVersionOverride>

Expand Down Expand Up @@ -105,8 +102,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Condition="'$(UseSystemTextJson)'!='True'"/>

<!-- Reference this package to avoid package downgrade errors. See https://github.com/dotnet/sdk/issues/3044 for details -->
<PackageReference Include="Microsoft.NETCore.Targets" ExcludeAssets="all" PrivateAssets="all" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

<Nullable>Enable</Nullable>
<IsPackable>true</IsPackable>

<UseSystemTextJson Condition="'$(TargetFramework)'!='netstandard2.0' And '$(TargetFramework)'!='net472'">True</UseSystemTextJson>
<DefineConstants Condition="'$(UseSystemTextJson)'=='True'">$(DefineConstants);USE_SYSTEM_TEXT_JSON</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,14 +22,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Condition="'$(UseSystemTextJson)'=='True'" />
<PackageReference Include="Newtonsoft.Json" Condition="'$(UseSystemTextJson)'!='True'" />
<PackageReference Include="Microsoft.Deployment.DotNet.Releases" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System" />
<Reference Include="System.Core" />
<PackageReference Include="System.Text.Json" VersionOverride="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
using Microsoft.NET.Sdk.Localization;
using static Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader;

#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
#else
using Newtonsoft.Json;
using JsonTokenType = Newtonsoft.Json.JsonToken;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand All @@ -27,19 +22,12 @@ public static class GlobalJsonReader

using var fileStream = File.OpenRead(globalJsonPath);

#if USE_SYSTEM_TEXT_JSON
var readerOptions = new JsonReaderOptions
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
};
var reader = new Utf8JsonStreamReader(fileStream, readerOptions);
#else
using var textReader = new StreamReader(fileStream, Encoding.UTF8, true);
using var jsonReader = new JsonTextReader(textReader);

var reader = new Utf8JsonStreamReader(jsonReader);
#endif

string? workloadVersion = null;

Expand Down Expand Up @@ -96,4 +84,3 @@ public static class GlobalJsonReader
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
using static Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader;
using System.Runtime.Serialization;

#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
#else
using Newtonsoft.Json;
using JsonTokenType = Newtonsoft.Json.JsonToken;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
using System.Globalization;
using System.Runtime.CompilerServices;


#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
#else
using JsonTokenType = Newtonsoft.Json.JsonToken;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if USE_SYSTEM_TEXT_JSON

using System.Buffers;
using System.Text.Json;

Expand Down Expand Up @@ -128,5 +126,3 @@ internal static class JsonTokenTypeExtensions
public static bool IsInt(this JsonTokenType tokenType) => tokenType == JsonTokenType.Number;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using Microsoft.NET.Sdk.Localization;
using FXVersion = Microsoft.DotNet.MSBuildSdkResolver.FXVersion;

#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
#else
using JsonTokenType = Newtonsoft.Json.JsonToken;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
using System.Text.Json.Serialization;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down Expand Up @@ -47,13 +45,11 @@ public WorkloadPackId(string id)
public static bool operator !=(WorkloadPackId a, WorkloadPackId b) => !a.Equals(b);
}

#if USE_SYSTEM_TEXT_JSON
internal class PackIdJsonConverter : JsonConverter<WorkloadPackId>
{
public override WorkloadPackId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
new(reader.GetString() ?? string.Empty);

public override void Write(Utf8JsonWriter writer, WorkloadPackId value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString());
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using Microsoft.DotNet.Workloads.Workload;
using Microsoft.NET.Sdk.Localization;
using FXVersion = Microsoft.DotNet.MSBuildSdkResolver.FXVersion;
#if USE_SYSTEM_TEXT_JSON
using System.Text.Json.Serialization;
#endif

namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down Expand Up @@ -674,9 +672,7 @@ public PackInfo(WorkloadPackId id, string version, WorkloadPackKind kind, string
/// <summary>
/// The workload pack ID. The NuGet package ID <see cref="ResolvedPackageId"/> may differ from this.
/// </summary>
#if USE_SYSTEM_TEXT_JSON
[JsonConverter(typeof(PackIdJsonConverter))]
#endif
public WorkloadPackId Id { get; }

public string Version { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
using Microsoft.DotNet.MSBuildSdkResolver;
using Strings = Microsoft.NET.Sdk.Localization.Strings;


#if USE_SYSTEM_TEXT_JSON
using System.Text.Json;
#else
using Newtonsoft.Json;
#endif


namespace Microsoft.NET.Sdk.WorkloadManifestReader
{
Expand Down Expand Up @@ -73,16 +67,12 @@ public static WorkloadSet FromDictionaryForJson(IDictionary<string, string?> dic

public static WorkloadSet FromJson(string json, SdkFeatureBand defaultFeatureBand)
{
#if USE_SYSTEM_TEXT_JSON
var jsonSerializerOptions = new JsonSerializerOptions()
{
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip
};
return FromDictionaryForJson(JsonSerializer.Deserialize<IDictionary<string, string>>(json, jsonSerializerOptions)!, defaultFeatureBand);
#else
return FromDictionaryForJson(JsonConvert.DeserializeObject<IDictionary<string, string>>(json)!, defaultFeatureBand);
#endif
}

public Dictionary<string, string> ToDictionaryForJson()
Expand All @@ -93,11 +83,7 @@ public Dictionary<string, string> ToDictionaryForJson()

public string ToJson()
{
#if USE_SYSTEM_TEXT_JSON
var json = JsonSerializer.Serialize(ToDictionaryForJson(), new JsonSerializerOptions() { WriteIndented = true });
#else
var json = JsonConvert.SerializeObject(ToDictionaryForJson(), Formatting.Indented);
#endif
return json;
}

Expand Down