diff --git a/src/Aspire.Hosting/Aspire.Hosting.csproj b/src/Aspire.Hosting/Aspire.Hosting.csproj index cd9d51fc88..f73f937b2c 100644 --- a/src/Aspire.Hosting/Aspire.Hosting.csproj +++ b/src/Aspire.Hosting/Aspire.Hosting.csproj @@ -1,4 +1,4 @@ - + $(NetCurrent) @@ -42,4 +42,8 @@ + + + + diff --git a/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs b/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs index 408d888d2f..ec8d8a0c56 100644 --- a/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs +++ b/src/Aspire.Hosting/Utils/LaunchProfileExtensions.cs @@ -145,6 +145,7 @@ private static bool TrySelectLaunchProfileFromAnnotation(ProjectResource project internal delegate bool LaunchProfileSelector(ProjectResource project, out string? launchProfile); [JsonSerializable(typeof(LaunchSettings))] +[JsonSourceGenerationOptions(ReadCommentHandling = JsonCommentHandling.Skip)] internal sealed partial class LaunchSetttingsSerializerContext : JsonSerializerContext { diff --git a/tests/Aspire.Hosting.Tests/LaunchSettingsSerializerContextTests.cs b/tests/Aspire.Hosting.Tests/LaunchSettingsSerializerContextTests.cs new file mode 100644 index 0000000000..952ee60d3d --- /dev/null +++ b/tests/Aspire.Hosting.Tests/LaunchSettingsSerializerContextTests.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text.Json; +using Xunit; + +namespace Aspire.Hosting.Tests; + +public class LaunchSettingsSerializerContextTests +{ + [Fact] + public void CommentsInLaunchSettingsJsonDoesNotThrow() + { + const string launchSettingsJson = """ + { + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + // comment + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5261", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } + """; + + // should not throw + JsonSerializer.Deserialize(launchSettingsJson, LaunchSetttingsSerializerContext.Default.LaunchSettings); + } +}