diff --git a/src/common/FilePreviewCommon/FilePreviewCommon.csproj b/src/common/FilePreviewCommon/FilePreviewCommon.csproj
index 28865605a06d..560fbf328704 100644
--- a/src/common/FilePreviewCommon/FilePreviewCommon.csproj
+++ b/src/common/FilePreviewCommon/FilePreviewCommon.csproj
@@ -2,6 +2,7 @@
+
PowerToys FilePreviewCommon
diff --git a/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs b/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs
new file mode 100644
index 000000000000..c6d596140765
--- /dev/null
+++ b/src/common/FilePreviewCommon/Formatters/FilePreviewJsonSerializerContext.cs
@@ -0,0 +1,14 @@
+// Copyright (c) Microsoft Corporation
+// The Microsoft Corporation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters;
+
+[JsonSourceGenerationOptions(WriteIndented = true)]
+[JsonSerializable(typeof(JsonDocument))]
+internal sealed partial class FilePreviewJsonSerializerContext : JsonSerializerContext
+{
+}
diff --git a/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs b/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs
index 91b7013c6fdd..7d969db56de3 100644
--- a/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs
+++ b/src/common/FilePreviewCommon/Formatters/JsonFormatter.cs
@@ -14,7 +14,6 @@ public class JsonFormatter : IFormatter
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
- WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};
@@ -28,7 +27,8 @@ public string Format(string value)
using (var jDocument = JsonDocument.Parse(value, new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip }))
{
- return JsonSerializer.Serialize(jDocument, _serializerOptions);
+ FilePreviewJsonSerializerContext context = new(_serializerOptions);
+ return JsonSerializer.Serialize(jDocument, context.JsonDocument);
}
}
}
diff --git a/src/common/FilePreviewCommon/MonacoHelper.cs b/src/common/FilePreviewCommon/MonacoHelper.cs
index e8442c0bff63..303cacbde287 100644
--- a/src/common/FilePreviewCommon/MonacoHelper.cs
+++ b/src/common/FilePreviewCommon/MonacoHelper.cs
@@ -6,9 +6,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
-using System.Reflection;
using System.Text.Json;
-
using Microsoft.PowerToys.FilePreviewCommon.Monaco.Formatters;
namespace Microsoft.PowerToys.FilePreviewCommon
@@ -38,15 +36,15 @@ public static class MonacoHelper
private static string GetRuntimeMonacoDirectory()
{
- string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
+ string baseDirectory = AppContext.BaseDirectory ?? string.Empty;
// If the executable is within "WinUI3Apps", correct the path first.
- if (Path.GetFileName(exePath) == "WinUI3Apps")
+ if (Path.GetFileName(baseDirectory) == "WinUI3Apps")
{
- exePath = Path.Combine(exePath, "..");
+ baseDirectory = Path.Combine(baseDirectory, "..");
}
- string monacoPath = Path.Combine(exePath, "Assets", "Monaco");
+ string monacoPath = Path.Combine(baseDirectory, "Assets", "Monaco");
return Directory.Exists(monacoPath) ?
monacoPath :
diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj
index 074b94ec5c3f..6d0fe10677e6 100644
--- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj
+++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj
@@ -1,7 +1,8 @@
-
+
+
enable
diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
index 89f480c792c1..189d72c9d474 100644
--- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
+++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs
@@ -20,7 +20,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
///
/// Win Form Implementation for Markdown Preview Handler.
///
- public class MarkdownPreviewHandlerControl : FormHandlerControl
+ public partial class MarkdownPreviewHandlerControl : FormHandlerControl
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IPath Path = FileSystem.Path;
@@ -66,7 +66,7 @@ public static string AssemblyDirectory
{
get
{
- string codeBase = Assembly.GetExecutingAssembly().Location;
+ string codeBase = AppContext.BaseDirectory;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);