diff --git a/src/BuiltInTools/DotNetWatchTasks/Utilities/IsExternalInit.cs b/src/BuiltInTools/DotNetWatchTasks/Utilities/IsExternalInit.cs
new file mode 100644
index 000000000000..7d1e00360964
--- /dev/null
+++ b/src/BuiltInTools/DotNetWatchTasks/Utilities/IsExternalInit.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Copied from:
+// https://github.com/dotnet/runtime/blob/218ef0f7776c2c20f6c594e3475b80f1fe2d7d08/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs
+
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices
+{
+ ///
+ /// Reserved to be used by the compiler for tracking metadata.
+ /// This class should not be used by developers in source code.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal static class IsExternalInit
+ {
+ }
+}
diff --git a/src/BuiltInTools/dotnet-watch/Internal/MSBuildFileSetResult.cs b/src/BuiltInTools/dotnet-watch/Internal/MSBuildFileSetResult.cs
index 16c91b4c5c23..295afb4d72b6 100644
--- a/src/BuiltInTools/dotnet-watch/Internal/MSBuildFileSetResult.cs
+++ b/src/BuiltInTools/dotnet-watch/Internal/MSBuildFileSetResult.cs
@@ -3,39 +3,55 @@
using System;
using System.Collections.Generic;
+using System.Runtime.Serialization;
namespace Microsoft.DotNet.Watcher.Internal
{
+ [DataContract]
internal sealed class MSBuildFileSetResult
{
- public string RunCommand { get; set; }
+ [DataMember]
+ public string RunCommand { get; init; }
- public string RunArguments { get; set; }
+ [DataMember]
+ public string RunArguments { get; init; }
- public string RunWorkingDirectory { get; set; }
+ [DataMember]
+ public string RunWorkingDirectory { get; init; }
- public bool IsNetCoreApp { get; set; }
+ [DataMember]
+ public bool IsNetCoreApp { get; init; }
- public string TargetFrameworkVersion { get; set; }
+ [DataMember]
+ public string TargetFrameworkVersion { get; init; }
- public string RuntimeIdentifier { get; set; }
+ [DataMember]
+ public string RuntimeIdentifier { get; init; }
- public string DefaultAppHostRuntimeIdentifier { get; set; }
+ [DataMember]
+ public string DefaultAppHostRuntimeIdentifier { get; init; }
- public Dictionary Projects { get; set; }
+ [DataMember]
+ public Dictionary Projects { get; init; }
}
+ [DataContract]
internal sealed class ProjectItems
{
- public List Files { get; set; } = new();
+ [DataMember]
+ public List Files { get; init; } = new();
- public List StaticFiles { get; set; } = new();
+ [DataMember]
+ public List StaticFiles { get; init; } = new();
}
+ [DataContract]
internal sealed class StaticFileItem
{
- public string FilePath { get; set; }
+ [DataMember]
+ public string FilePath { get; init; }
- public string StaticWebAssetPath { get; set; }
+ [DataMember]
+ public string StaticWebAssetPath { get; init; }
}
}
diff --git a/src/Tests/dotnet-watch.Tests/FileSetSerializerTests.cs b/src/Tests/dotnet-watch.Tests/FileSetSerializerTests.cs
new file mode 100644
index 000000000000..495142f9d6b1
--- /dev/null
+++ b/src/Tests/dotnet-watch.Tests/FileSetSerializerTests.cs
@@ -0,0 +1,49 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System.IO;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.DotNet.Watcher.Internal;
+using Xunit;
+
+namespace Microsoft.DotNet.Watcher.Tools;
+
+public class FileSetSerializerTests
+{
+ [Fact]
+ public async Task Serialize()
+ {
+ var fileSetResult = new MSBuildFileSetResult()
+ {
+ IsNetCoreApp = true,
+ TargetFrameworkVersion = "net5.0",
+ RuntimeIdentifier = "win-arm64",
+ DefaultAppHostRuntimeIdentifier = "",
+ RunCommand = "run",
+ RunArguments = "args",
+ RunWorkingDirectory = "dir",
+ Projects = new() { { "proj", new() { Files = new() { "a.cs", "b.cs" }, StaticFiles = new() { new() { FilePath = "path1", StaticWebAssetPath = "path2" } } } } }
+ };
+
+ using var stream = new MemoryStream();
+
+ var serializer = new DataContractJsonSerializer(fileSetResult.GetType(), new DataContractJsonSerializerSettings
+ {
+ UseSimpleDictionaryFormat = true,
+ });
+
+ using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream, Encoding.UTF8, ownsStream: false, indent: true))
+ {
+ serializer.WriteObject(writer, fileSetResult);
+ }
+
+ stream.Position = 0;
+
+ await JsonSerializer.DeserializeAsync(stream, cancellationToken: CancellationToken.None);
+ }
+}
diff --git a/src/Tests/dotnet-watch.Tests/dotnet-watch.Tests.csproj b/src/Tests/dotnet-watch.Tests/dotnet-watch.Tests.csproj
index c126799ec11f..7cac2bac18ac 100644
--- a/src/Tests/dotnet-watch.Tests/dotnet-watch.Tests.csproj
+++ b/src/Tests/dotnet-watch.Tests/dotnet-watch.Tests.csproj
@@ -3,6 +3,7 @@
Exe
$(ToolsetTargetFramework)
MicrosoftAspNetCore
+ Microsoft.DotNet.Watcher.Tools