Skip to content

A Swiss Army knife for developers.

Brought back support of plugins on Mac, Windows and Linux. (#821)

Etienne BAUDOUX9edf24b339c0
diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json
index 08a9bbac2..9e6eb7678 100644
--- a/.nuke/build.schema.json
+++ b/.nuke/build.schema.json
@@ -95,6 +95,7 @@
"type": "string",
"enum": [
"BuildGenerators",
+ "BuildPlugins",
"Clean",
"PreliminaryCheck",
"Publish",
@@ -111,6 +112,7 @@
"type": "string",
"enum": [
"BuildGenerators",
+ "BuildPlugins",
"Clean",
"PreliminaryCheck",
"Publish",
diff --git a/src/DevToys-MacOS.sln b/src/DevToys-MacOS.sln
index dbcd74245..a2a951d4b 100644
--- a/src/DevToys-MacOS.sln
+++ b/src/DevToys-MacOS.sln
@@ -35,6 +35,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "desktops", "desktops", "{22EE9386-CEFA-47D8-97B2-09A63EDF7F2E}"
+ ProjectSection(SolutionItems) = preProject
+ app\dev\platforms\desktop\Directory.Build.props = app\dev\platforms\desktop\Directory.Build.props
+ app\dev\platforms\desktop\Directory.Build.targets = app\dev\platforms\desktop\Directory.Build.targets
+ EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.CLI", "app\dev\platforms\desktop\DevToys.CLI\DevToys.CLI.csproj", "{8C72D38A-658D-4C9D-B0AD-2DA975BE7826}"
ProjectSection(ProjectDependencies) = postProject
@@ -63,6 +67,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Business", "app\dev\DevToys.Business\DevToys.Business.csproj", "{AC565EE5-BF5F-4D14-8F40-DFB3E06D9724}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.MacOS", "app\dev\platforms\desktop\DevToys.MacOS\DevToys.MacOS.csproj", "{2EBD314E-B862-41B8-AB9E-F6371EB50666}"
+ ProjectSection(ProjectDependencies) = postProject
+ {B6D48157-5257-4B60-B065-3B231B610A54} = {B6D48157-5257-4B60-B065-3B231B610A54}
+ EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Blazor", "app\dev\DevToys.Blazor\DevToys.Blazor.csproj", "{608B24BF-8491-4167-932F-9CF23C97FDEE}"
EndProject
diff --git a/src/DevToys-Windows.sln b/src/DevToys-Windows.sln
index 9dea81d62..3d61e29d5 100644
--- a/src/DevToys-Windows.sln
+++ b/src/DevToys-Windows.sln
@@ -36,6 +36,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "desktops", "desktops", "{22EE9386-CEFA-47D8-97B2-09A63EDF7F2E}"
+ ProjectSection(SolutionItems) = preProject
+ app\dev\platforms\desktop\Directory.Build.props = app\dev\platforms\desktop\Directory.Build.props
+ app\dev\platforms\desktop\Directory.Build.targets = app\dev\platforms\desktop\Directory.Build.targets
+ EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.CLI", "app\dev\platforms\desktop\DevToys.CLI\DevToys.CLI.csproj", "{8C72D38A-658D-4C9D-B0AD-2DA975BE7826}"
ProjectSection(ProjectDependencies) = postProject
@@ -69,7 +73,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Business", "app\dev
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Blazor", "app\dev\DevToys.Blazor\DevToys.Blazor.csproj", "{565D2497-6078-4558-911C-EA7D3A25AB16}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevToys.Windows", "app\dev\platforms\desktop\DevToys.Windows\DevToys.Windows.csproj", "{48531D2E-83C6-49F2-9ADD-C9490386718B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Windows", "app\dev\platforms\desktop\DevToys.Windows\DevToys.Windows.csproj", "{48531D2E-83C6-49F2-9ADD-C9490386718B}"
+ ProjectSection(ProjectDependencies) = postProject
+ {B6D48157-5257-4B60-B065-3B231B610A54} = {B6D48157-5257-4B60-B065-3B231B610A54}
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj b/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
index c4b38011a..e6f63c0b2 100644
--- a/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
+++ b/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
@@ -24,7 +24,6 @@
<ProjectReference Include="..\DevToys.Business\DevToys.Business.csproj" />
<ProjectReference Include="..\DevToys.Core\DevToys.Core.csproj" />
<ProjectReference Include="..\DevToys.Localization\DevToys.Localization.csproj" />
- <ProjectReference Include="..\DevToys.Tools\DevToys.Tools.csproj" />
</ItemGroup>
<ItemGroup>
diff --git a/src/app/dev/DevToys.Core/Mef/MefComposer.cs b/src/app/dev/DevToys.Core/Mef/MefComposer.cs
index 2f4c0d124..15cc8315c 100644
--- a/src/app/dev/DevToys.Core/Mef/MefComposer.cs
+++ b/src/app/dev/DevToys.Core/Mef/MefComposer.cs
@@ -13,6 +13,7 @@ public sealed partial class MefComposer : IDisposable
{
private readonly ILogger _logger;
private readonly Assembly[] _assemblies;
+ private readonly string? _pluginFolder;
private readonly object[] _customExports;
private bool _isExportProviderDisposed = true;
@@ -20,7 +21,7 @@ public sealed partial class MefComposer : IDisposable
public CompositionContainer ExportProvider { get; private set; }
- public MefComposer(Assembly[]? assemblies = null, params object[] customExports)
+ public MefComposer(Assembly[]? assemblies = null, string? pluginFolder = null, params object[] customExports)
{
if (Provider is not null)
{
@@ -30,6 +31,7 @@ public sealed partial class MefComposer : IDisposable
_logger = this.Log();
_assemblies = assemblies ?? Array.Empty<Assembly>();
+ _pluginFolder = pluginFolder;
_customExports = customExports ?? Array.Empty<object>();
ExportProvider = InitializeMef();
@@ -74,6 +76,21 @@ public sealed partial class MefComposer : IDisposable
catalog.Catalogs.Add(new AssemblyCatalog(assembly));
}
+ // Dynamically load assemblies coming from the Plugin repository folder and
+ // try to discover MEF extensions in them.
+ foreach (string pluginFolder in GetPotentialPluginFolders())
+ {
+ LogDiscoveringPlugin(pluginFolder);
+ try
+ {
+ catalog.Catalogs.Add(new RecursiveDirectoryCatalog(pluginFolder));
+ }
+ catch (Exception ex)
+ {
+ LogDiscoveringPluginFault(ex, pluginFolder);
+ }
+ }
+
// Compose MEF.
var container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
@@ -94,6 +111,36 @@ public sealed partial class MefComposer : IDisposable
return ExportProvider;
}
+ private IEnumerable<string> GetPotentialPluginFolders()
+ {
+ // TODO: Maybe plugins should be placed in the app's LocalStorage instead?
+ string appFolder = AppContext.BaseDirectory;
+ if (!string.IsNullOrEmpty(appFolder))
+ {
+ string pluginFolder;
+ if (!string.IsNullOrEmpty(_pluginFolder))
+ {
+ pluginFolder = Path.Combine(appFolder!, _pluginFolder!);
+ }
+ else
+ {
+ pluginFolder = Path.Combine(appFolder!, "Plugins");
+ }
+ if (Directory.Exists(pluginFolder))
+ {
+ return Directory.EnumerateDirectories(pluginFolder, "*", SearchOption.TopDirectoryOnly);
+ }
+ }
+
+ return Array.Empty<string>();
+ }
+
[LoggerMessage(0, LogLevel.Information, "MEF composed in {duration} ms")]
partial void LogMefComposition(double duration);
+
+ [LoggerMessage(1, LogLevel.Information, "Discovering plugin in '{pluginFolder}'...")]
+ partial void LogDiscoveringPlugin(string pluginFolder);
+
+ [LoggerMessage(2, LogLevel.Error, "Unable to load plugin in '{pluginFolder}'...")]
+ partial void LogDiscoveringPluginFault(Exception ex, string pluginFolder);
}
diff --git a/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs b/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs
new file mode 100644
index 000000000..02a5f9cc1
--- /dev/null
+++ b/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs
@@ -0,0 +1,133 @@
+using System.ComponentModel.Composition.Hosting;
+using System.ComponentModel.Composition.Primitives;
+using System.Globalization;
+using System.IO;
+using System.Reflection;
+
+namespace DevToys.Core.Mef;
+
+/// <summary>
+/// Extends <see cref="DirectoryCatalog"/> to support discovery of parts in sub-directories.
+/// </summary>
+internal sealed class RecursiveDirectoryCatalog : ComposablePartCatalog, INotifyComposablePartCatalogChanged, ICompositionElement
+{
+ private readonly string _path;
+ private AggregateCatalog? _aggregateCatalog;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RecursiveDirectoryCatalog"/> class with <see cref="ComposablePartDefinition"/> objects based on all the DLL files in the specified directory path and its sub-directories.
+ /// </summary>
+ /// <param name="path">Path to the directory to scan for assemblies to add to the catalog.</param>
+ public RecursiveDirectoryCatalog(string path)
+ : this(path, "*.dll")
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="RecursiveDirectoryCatalog"/> class with <see cref="ComposablePartDefinition"/> objects based on the specified search pattern in the specified directory path path and its sub-directories.
+ /// </summary>
+ /// <param name="path">Path to the directory to scan for assemblies to add to the catalog.</param>
+ /// <param name="searchPattern">The pattern to search with. The format of the pattern should be the same as specified for GetFiles.</param>
+ /// <exception cref="ArgumentNullException">The value of the <paramref name="path"/> parameter was <see langword="null"/>.</exception>
+ public RecursiveDirectoryCatalog(string path, string searchPattern)
+ {
+ Guard.IsNotNull(path);
+
+ _path = path;
+
+ Initialize(path, searchPattern);
+ }
+
+ private static IEnumerable<string> GetFoldersRecursive(string path)
+ {
+ var result = new List<string> { path };
+ foreach (string child in Directory.GetDirectories(path))
+ {
+ result.AddRange(GetFoldersRecursive(child));
+ }
+ return result;
+ }
+
+ private void Initialize(string path, string searchPattern)
+ {
+ IEnumerable<string> files
+ = Directory.EnumerateFiles(path, searchPattern, SearchOption.AllDirectories);
+
+ _aggregateCatalog = new AggregateCatalog();
+
+ _aggregateCatalog.Changed += (o, e) =>
+ {
+ Changed?.Invoke(o, e);
+ };
+
+ _aggregateCatalog.Changing += (o, e) =>
+ {
+ Changing?.Invoke(o, e);
+ };
+
+ foreach (string file in files)
+ {
+ try
+ {
+ var asmCat = new AssemblyCatalog(file);
+
+ // Force MEF to load the plugin and figure out if there are any exports
+ // good assemblies will not throw the RTLE exception and can be added to the catalog
+ if (asmCat.Parts.ToList().Count > 0)
+ {
+ _aggregateCatalog.Catalogs.Add(asmCat);
+ }
+ }
+ catch (ReflectionTypeLoadException)
+ {
+ }
+ catch (BadImageFormatException)
+ {
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the part definitions that are contained in the recursive directory catalog. (Overrides ComposablePartCatalog.Parts.)
+ /// </summary>
+ public override IQueryable<ComposablePartDefinition> Parts
+ {
+ get
+ {
+ Guard.IsNotNull(_aggregateCatalog);
+ return _aggregateCatalog.Parts;
+ }
+ }
+
+ /// <summary>
+ /// Occurs when the contents of the catalog has changed.
+ /// </summary>
+ public event EventHandler<ComposablePartCatalogChangeEventArgs>? Changed;
+
+ /// <summary>
+ /// Occurs when the catalog is changing.
+ /// </summary>
+ public event EventHandler<ComposablePartCatalogChangeEventArgs>? Changing;
+
+ private string GetDisplayName()
+ {
+ return string.Format(
+ CultureInfo.CurrentCulture,
+ "{0} (RecusrivePath=\"{1}\")", new[] { GetType().Name, _path });
+ }
+
+ public override string ToString()
+ {
+ return GetDisplayName();
+ }
+
+ /// <summary>
+ /// Gets the display name of the directory catalog.
+ /// </summary>
+ string ICompositionElement.DisplayName => GetDisplayName();
+
+ /// <summary>
+ /// Gets the composition element from which the directory catalog originated.
+ /// </summary>
+ ICompositionElement? ICompositionElement.Origin => null;
+}
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
index a28cc61e3..abdcdae8a 100644
--- a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
+++ b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
@@ -46,4 +46,17 @@
<PackageReference Include="Uno.Core.Extensions.Logging.Singleton" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
+
+ <Target Name="CopyPluginAfterBuild" AfterTargets="Build">
+ <ItemGroup>
+ <PluginOutput Include="$(OutputPath)\**\*" />
+ </ItemGroup>
+ <Copy
+ SourceFiles="@(PluginOutput)"
+ DestinationFolder="$(RepoRoot)bin\$(Configuration)\Plugins\DevToys.Tools"
+ SkipUnchangedFiles="false"
+ OverwriteReadOnlyFiles="true"
+ Retries="10"
+ RetryDelayMilliseconds="1000" />
+ </Target>
</Project>
\ No newline at end of file
diff --git a/src/app/dev/Directory.Build.props b/src/app/dev/Directory.Build.props
index 9f8d862a0..d3e680c7e 100644
--- a/src/app/dev/Directory.Build.props
+++ b/src/app/dev/Directory.Build.props
@@ -8,13 +8,11 @@
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
- <!-- Workaround for https://github.com/unoplatform/uno/discussions/5007, to remove when original VS issue is fixed. -->
- <SynthesizeLinkMetadata>true</SynthesizeLinkMetadata>
-
<!-- https://github.com/dotnet/project-system/blob/main/docs/build-acceleration.md -->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
- <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
+ <!-- AOT & Trim settings -->
+ <!-- <EnableTrimAnalyzer>true</EnableTrimAnalyzer> -->
<NoWarm>$(NoWarm);IL2007;IL2091;IL2077;IL2055;IL2075</NoWarm>
</PropertyGroup>
@@ -25,14 +23,15 @@
<!-- AOT & Trim settings -->
<!-- https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/ -->
<!-- https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?source=recommendations&pivots=dotnet-7-0 -->
- <TrimMode>partial</TrimMode>
- <StripSymbols>true</StripSymbols>
+ <!--<TrimMode>partial</TrimMode>
+ <StripSymbols>true</StripSymbols>-->
+ <!--<BuiltInComInteropSupport>false</BuiltInComInteropSupport>-->
</PropertyGroup>
<ItemGroup>
- <TrimmerRootDescriptor Include="$(RepoRoot)\src\app\dev\shared\LinkerConfig.xml" Link="Properties\$(MSBuildProjectName).xml">
+ <!--<TrimmerRootDescriptor Include="$(RepoRoot)\src\app\dev\shared\LinkerConfig.xml" Link="Properties\$(MSBuildProjectName).xml">
<LogicalName>$(MSBuildProjectName).xml</LogicalName>
- </TrimmerRootDescriptor>
+ </TrimmerRootDescriptor>-->
<Compile Include="$(RepoRoot)\src\app\dev\shared\GlobalUsings.cs" Link="Properties\GlobalUsings.cs" />
<Compile Include="$(RepoRoot)\src\app\dev\shared\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
<Compile Include="$(RepoRoot)\src\app\dev\shared\SharedAssemblyVersion.cs" Link="Properties\SharedAssemblyVersion.cs" />
diff --git a/src/app/dev/platforms/desktop/DevToys.CLI/DevToys.CLI.csproj b/src/app/dev/platforms/desktop/DevToys.CLI/DevToys.CLI.csproj
index b6d19622e..4e7379659 100644
--- a/src/app/dev/platforms/desktop/DevToys.CLI/DevToys.CLI.csproj
+++ b/src/app/dev/platforms/desktop/DevToys.CLI/DevToys.CLI.csproj
@@ -17,6 +17,5 @@
<ItemGroup>
<ProjectReference Include="..\..\..\DevToys.Api\DevToys.Api.csproj" />
<ProjectReference Include="..\..\..\DevToys.Core\DevToys.Core.csproj" />
- <ProjectReference Include="..\..\..\DevToys.Tools\DevToys.Tools.csproj" />
</ItemGroup>
</Project>
diff --git a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
index 250a90cc7..7119172e7 100644
--- a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
+++ b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
@@ -6,7 +6,6 @@ using DevToys.CLI.Core.FileStorage;
using DevToys.Core;
using DevToys.Core.Logging;
using DevToys.Core.Mef;
-using DevToys.Tools;
using Microsoft.Extensions.Logging;
namespace DevToys.CLI;
@@ -67,8 +66,7 @@ internal partial class Program
= new MefComposer(
new[]
{
- typeof(DevToysToolsResourceManagerAssemblyIdentifier).Assembly,
- typeof(Program).Assembly
+ typeof(Program).Assembly
});
// Get all the command line tools.
diff --git a/src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs b/src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs
index a9a8cc842..36b34a6c6 100644
--- a/src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs
+++ b/src/app/dev/platforms/desktop/DevToys.MacOS/Core/FileStorage.cs
@@ -5,7 +5,7 @@ namespace DevToys.MacOS.Core;
[Export(typeof(IFileStorage))]
internal sealed class FileStorage : IFileStorage
{
- public string AppCacheDirectory => FileSystem.CacheDirectory;
+ public string AppCacheDirectory => Path.Combine(FileSystem.CacheDirectory, "com.etiennebaudoux.devtoys");
public bool FileExists(string relativeOrAbsoluteFilePath)
{
diff --git a/src/app/dev/platforms/desktop/DevToys.MacOS/DevToys.MacOS.csproj b/src/app/dev/platforms/desktop/DevToys.MacOS/DevToys.MacOS.csproj
index f57ac3a19..96c83a619 100644
--- a/src/app/dev/platforms/desktop/DevToys.MacOS/DevToys.MacOS.csproj
+++ b/src/app/dev/platforms/desktop/DevToys.MacOS/DevToys.MacOS.csproj
@@ -26,7 +26,11 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);__MACCATALYST__</DefineConstants>
<RuntimeIdentifiers>maccatalyst-arm64</RuntimeIdentifiers>
+
+ <!-- The following 3 properties disable trimming and AOT. This allow us to load plugins at runtime. -->
<UseInterpreter>true</UseInterpreter>
+ <MtouchLink>None</MtouchLink>
+ <MtouchInterpreter>all</MtouchInterpreter>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<CodeSignEntitlements>Platforms/MacCatalyst/Entitlements.Debug.plist</CodeSignEntitlements>
diff --git a/src/app/dev/platforms/desktop/DevToys.MacOS/MauiProgram.cs b/src/app/dev/platforms/desktop/DevToys.MacOS/MauiProgram.cs
index fe01607de..2e8ec4fe2 100644
--- a/src/app/dev/platforms/desktop/DevToys.MacOS/MauiProgram.cs
+++ b/src/app/dev/platforms/desktop/DevToys.MacOS/MauiProgram.cs
@@ -4,21 +4,23 @@ using DevToys.Business.ViewModels;
using DevToys.Core.Logging;
using DevToys.Core.Mef;
using DevToys.MacOS.Core;
-using DevToys.Tools;
using Microsoft.Extensions.Logging;
+using Uno.Extensions;
using PredefinedSettings = DevToys.Core.Settings.PredefinedSettings;
namespace DevToys.MacOS;
-public static partial class MauiProgram
+public partial class MauiProgram
{
- internal static MefComposer? MefComposer;
+ private ILogger? _logger;
+ private MauiApp? _app;
- private static MauiApp? app;
- private static ILogger? logger;
+ internal MefComposer? MefComposer;
- public static MauiApp CreateMauiApp()
+ public MauiApp CreateMauiApp()
{
+ Guard.IsNull(_app);
+
DateTime startTime = DateTime.Now;
MauiAppBuilder builder = MauiApp.CreateBuilder();
@@ -44,16 +46,14 @@ public static partial class MauiProgram
MefComposer
= new MefComposer(
new[] {
- typeof(DevToysToolsResourceManagerAssemblyIdentifier).Assembly,
typeof(MainWindowViewModel).Assembly
- });
+ },
+ pluginFolder: "../Resources/Plugins");
LogInitialization((DateTime.Now - startTime).TotalMilliseconds);
LogAppStarting();
- MauiApp app = builder.Build();
-
- MauiProgram.app = app;
+ _app = builder.Build();
// Set the user-defined language.
string? languageIdentifier = MefComposer.Provider.Import<ISettingsProvider>().GetSetting(PredefinedSettings.Language);
@@ -62,15 +62,15 @@ public static partial class MauiProgram
?? LanguageManager.Instance.AvailableLanguages[0];
LanguageManager.Instance.SetCurrentCulture(languageDefinition);
- return app;
+ return _app;
}
- private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
+ private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUnhandledException((Exception)e.ExceptionObject);
}
- private static ServiceProvider InitializeServices(IServiceCollection serviceCollection)
+ private ServiceProvider InitializeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddMauiBlazorWebView();
@@ -100,23 +100,23 @@ public static partial class MauiProgram
ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = loggerFactory;
- logger = loggerFactory.CreateLogger<MauiApp>();
+ _logger = this.Log();
return serviceProvider;
}
- private static void LogUnhandledException(Exception exception)
+ private void LogUnhandledException(Exception exception)
{
- logger?.LogCritical(0, exception, "Unhandled exception !!! (╯°□°)╯︵ ┻━┻");
+ _logger?.LogCritical(0, exception, "Unhandled exception !!! (╯°□°)╯︵ ┻━┻");
}
- private static void LogAppStarting()
+ private void LogAppStarting()
{
- logger?.LogInformation(1, "App is starting...");
+ _logger?.LogInformation(1, "App is starting...");
}
- private static void LogInitialization(double duration)
+ private void LogInitialization(double duration)
{
- logger?.LogInformation(2, "MEF, services and logging initialized in {duration} ms", duration);
+ _logger?.LogInformation(2, "MEF, services and logging initialized in {duration} ms", duration);
}
}
diff --git a/src/app/dev/platforms/desktop/DevToys.MacOS/Platforms/MacCatalyst/AppDelegate.cs b/src/app/dev/platforms/desktop/DevToys.MacOS/Platforms/MacCatalyst/AppDelegate.cs
index b56953685..ebf54a514 100644
--- a/src/app/dev/platforms/desktop/DevToys.MacOS/Platforms/MacCatalyst/AppDelegate.cs
+++ b/src/app/dev/platforms/desktop/DevToys.MacOS/Platforms/MacCatalyst/AppDelegate.cs
@@ -5,5 +5,7 @@ namespace DevToys.MacOS;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
- protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
+ private readonly MauiProgram _program = new();
+
+ protected override MauiApp CreateMauiApp() => _program.CreateMauiApp();
}
diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/DevToys.Windows.csproj b/src/app/dev/platforms/desktop/DevToys.Windows/DevToys.Windows.csproj
index 7afe2e467..978e52625 100644
--- a/src/app/dev/platforms/desktop/DevToys.Windows/DevToys.Windows.csproj
+++ b/src/app/dev/platforms/desktop/DevToys.Windows/DevToys.Windows.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
- <TargetFramework>$(NetCoreWindows10)</TargetFramework>
+ <TargetFramework>$(NetCoreWindows)</TargetFramework>
<TargetPlatformMinVersion>7.0</TargetPlatformMinVersion>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
diff --git a/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs b/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
index 8c3248c96..60d780934 100644
--- a/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
+++ b/src/app/dev/platforms/desktop/DevToys.Windows/MainWindow.xaml.cs
@@ -1,11 +1,9 @@
-using System;
-using DevToys.Api;
+using DevToys.Api;
using DevToys.Blazor.Core.Languages;
using DevToys.Business.ViewModels;
using DevToys.Core;
using DevToys.Core.Logging;
using DevToys.Core.Mef;
-using DevToys.Tools;
using DevToys.Windows.Controls;
using DevToys.Windows.Core;
using Microsoft.AspNetCore.Components.WebView;
@@ -42,7 +40,6 @@ public partial class MainWindow : MicaWindowWithOverlay
_mefComposer
= new MefComposer(
new[] {
- typeof(DevToysToolsResourceManagerAssemblyIdentifier).Assembly,
typeof(MainWindowViewModel).Assembly
});
diff --git a/src/app/dev/platforms/desktop/Directory.Build.props b/src/app/dev/platforms/desktop/Directory.Build.props
new file mode 100644
index 000000000..218874157
--- /dev/null
+++ b/src/app/dev/platforms/desktop/Directory.Build.props
@@ -0,0 +1,10 @@
+<Project>
+ <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
+
+ <!-- Include DevToys.Tools and other plugins to the output -->
+ <ItemGroup>
+ <Content Include="$(RepoRoot)bin\$(Configuration)\Plugins\**\*" Link="Plugins\%(RecursiveDir)%(Filename)%(Extension)">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/src/app/dev/platforms/desktop/Directory.Build.targets b/src/app/dev/platforms/desktop/Directory.Build.targets
new file mode 100644
index 000000000..314b4fa3e
--- /dev/null
+++ b/src/app/dev/platforms/desktop/Directory.Build.targets
@@ -0,0 +1,18 @@
+<Project>
+ <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
+
+ <Target Name="ImportPluginOnPublish" BeforeTargets="Publish">
+ <Message Text="Importing plugins..." Importance="high" />
+ <ItemGroup>
+ <PluginOutput Include="$(RepoRoot)bin\$(Configuration)\Plugins\**\*" />
+ </ItemGroup>
+ <Copy
+ SourceFiles="@(PluginOutput)"
+ DestinationFolder="$(PublishDir)\Plugins\%(RecursiveDir)"
+ SkipUnchangedFiles="true"
+ OverwriteReadOnlyFiles="true"
+ Retries="10"
+ RetryDelayMilliseconds="1000" />
+ <Message Text="Plugins imported!" Importance="high" />
+ </Target>
+</Project>
\ No newline at end of file
diff --git a/src/app/dev/shared/LinkerConfig.xml b/src/app/dev/shared/LinkerConfig.xml
index 307344416..83eb0ba51 100644
--- a/src/app/dev/shared/LinkerConfig.xml
+++ b/src/app/dev/shared/LinkerConfig.xml
@@ -20,13 +20,13 @@
<type fullname="System.Linq.Expressions*" />
</assembly>
<assembly fullname="System.Private.CoreLib" />
- <assembly fullname="Uno.UI" />
<assembly fullname="Microsoft.Extensions.Options" />
<assembly fullname="DevToys.API" />
<assembly fullname="DevToys.Core" />
- <assembly fullname="DevToys.CLI" />
<assembly fullname="DevToys.Localization" />
<assembly fullname="DevToys.Blazor" />
<assembly fullname="DevToys.Business" />
- <assembly fullname="DevToys.Tools" />
+ <assembly fullname="DevToys.CLI" />
+ <assembly fullname="DevToys.Windows" />
+ <assembly fullname="DevToys.MacOS" />
</linker>
\ No newline at end of file
diff --git a/src/build/Build.cs b/src/build/Build.cs
index 2e18481d0..f105c33e3 100644
--- a/src/build/Build.cs
+++ b/src/build/Build.cs
@@ -117,12 +117,30 @@ class Build : NukeBuild
.SetVerbosity(DotNetVerbosity.Quiet)));
});
+ Target BuildPlugins => _ => _
+ .DependentFor(Publish)
+ .After(Restore)
+ .After(SetVersion)
+ .After(BuildGenerators)
+ .Executes(() =>
+ {
+ Log.Information($"Building plugins ...");
+ Project project = WindowsSolution!.GetProject("DevToys.Tools");
+ DotNetBuild(s => s
+ .SetProjectFile(project)
+ .SetConfiguration(Configuration)
+ .SetSelfContained(false)
+ .SetPublishTrimmed(false)
+ .SetVerbosity(DotNetVerbosity.Quiet));
+ });
+
#pragma warning disable IDE0051 // Remove unused private members
Target UnitTests => _ => _
.DependentFor(Publish)
.After(Restore)
.After(SetVersion)
.After(BuildGenerators)
+ .After(BuildPlugins)
.OnlyWhenDynamic(() => RunTests)
.Executes(() =>
{
@@ -144,119 +162,90 @@ class Build : NukeBuild
{
if (PlatformTargets!.Contains(PlatformTarget.Windows))
{
- // DevToys MAUI Blazor
- foreach (DotnetParameters dotnetParameters in GetDotnetParametersForMauiBlazorApp())
- {
- Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
- DotNetPublish(s => s
- .SetProject(dotnetParameters.ProjectOrSolutionPath)
- .SetConfiguration(Configuration)
- .SetFramework(dotnetParameters.TargetFramework)
- .SetRuntime(dotnetParameters.RuntimeIdentifier)
- .SetSelfContained(true)
- .SetPublishSingleFile(false)
- .SetPublishReadyToRun(false)
- .SetPublishTrimmed(dotnetParameters.Portable)
- .SetVerbosity(DotNetVerbosity.Quiet)
- .SetProcessArgumentConfigurator(_ => _
- .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
- .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
- .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));
- }
-
- // DevToys WASDK
- foreach (DotnetParameters dotnetParameters in GetDotnetParametersForWasdkApp())
- {
- Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier + (dotnetParameters.Portable ? "-Portable" : string.Empty)} ...");
- DotNetPublish(s => s
- .SetProject(dotnetParameters.ProjectOrSolutionPath)
- .SetConfiguration(Configuration)
- .SetFramework(dotnetParameters.TargetFramework)
- .SetRuntime(dotnetParameters.RuntimeIdentifier)
- .SetPlatform(dotnetParameters.Platform)
- .SetSelfContained(true)
- .SetPublishSingleFile(false)
- .SetPublishReadyToRun(true)
- // TODO: Enable trimming. There are some things we will need to workaround to enable it.
- // Trimming makes that we can't do COM invokes like User32.dll using DllImport.
- // We use it at least in Backdrop.Windows.cs. We will need to find a workaround by either
- // upgrading WASDK and use `SystemBackdrop = new MicaBackdrop();` and/or by writing our own
- // wrapper like here: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities?source=recommendations#built-in-com-marshalling
- .SetPublishTrimmed(false)
- //.SetPublishTrimmed(dotnetParameters.Portable)
- .SetVerbosity(DotNetVerbosity.Quiet)
- .SetProcessArgumentConfigurator(_ => _
- .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
- .Add("/p:Unpackaged=" + dotnetParameters.Portable)
- .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
- .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));
- }
+ PublishWindowsApp();
}
if (PlatformTargets!.Contains(PlatformTarget.MacCatalyst))
{
- // DevToys MAUI Blazor
- foreach (DotnetParameters dotnetParameters in GetDotnetParametersForMauiBlazorApp())
- {
- Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
- DotNetBuild(s => s
- .SetProjectFile(dotnetParameters.ProjectOrSolutionPath)
- .SetConfiguration(Configuration)
- .SetPublishSingleFile(false) // Not supported by MacCatalyst as it would require UseAppHost to be true, which isn't supported on Mac
- .SetPublishReadyToRun(false)
- .SetPublishTrimmed(true) /* Required True for MacCatalyst ? */
- .SetVerbosity(DotNetVerbosity.Quiet)
- .SetNoRestore(true) /* workaround for https://github.com/xamarin/xamarin-macios/issues/15664#issuecomment-1233123515 */
- .SetProcessArgumentConfigurator(_ => _
- .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
- .Add("/p:CreatePackage=True") /* Will create an installable .pkg */
- .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
- .SetOutputDirectory(RootDirectory / "publish" / dotnetParameters.OutputPath));
- }
-
- // DevToys Uno Mac Catalyst
- foreach (DotnetParameters dotnetParameters in GetDotnetParametersForMacOSApp())
- {
- Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
- DotNetBuild(s => s
- .SetProjectFile(dotnetParameters.ProjectOrSolutionPath)
- .SetConfiguration(Configuration)
- .SetPublishSingleFile(false) // Not supported by MacCatalyst as it would require UseAppHost to be true, which isn't supported on Mac
- .SetPublishReadyToRun(false)
- .SetPublishTrimmed(true) /* Required True for MacCatalyst ? */
- .SetVerbosity(DotNetVerbosity.Quiet)
- .SetNoRestore(true) /* workaround for https://github.com/xamarin/xamarin-macios/issues/15664#issuecomment-1233123515 */
- .SetProcessArgumentConfigurator(_ => _
- .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
- .Add("/p:CreatePackage=True") /* Will create an installable .pkg */
- .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
- .SetOutputDirectory(RootDirectory / "publish" / dotnetParameters.OutputPath));
- }
+ PublishMacApp();
}
if (PlatformTargets!.Contains(PlatformTarget.CLI))
{
- // DevToys CLI
- foreach (DotnetParameters dotnetParameters in GetDotnetParametersForCliApp())
- {
- Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
- DotNetPublish(s => s
- .SetProject(dotnetParameters.ProjectOrSolutionPath)
- .SetConfiguration(Configuration)
- .SetFramework(dotnetParameters.TargetFramework)
- .SetRuntime(dotnetParameters.RuntimeIdentifier)
- .SetSelfContained(dotnetParameters.Portable)
- .SetPublishSingleFile(true)
- .SetPublishReadyToRun(true)
- .SetPublishTrimmed(dotnetParameters.Portable)
- .SetVerbosity(DotNetVerbosity.Quiet)
- .SetProcessArgumentConfigurator(_ => _
- .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
- .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));
- }
+ PublishCliApp();
}
});
+ void PublishWindowsApp()
+ {
+ // DevToys WPF
+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForWindowsApp())
+ {
+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier + (dotnetParameters.Portable ? "-Portable" : string.Empty)} ...");
+ DotNetPublish(s => s
+ .SetProject(dotnetParameters.ProjectOrSolutionPath)
+ .SetConfiguration(Configuration)
+ .SetFramework(dotnetParameters.TargetFramework)
+ .SetRuntime(dotnetParameters.RuntimeIdentifier)
+ .SetPlatform(dotnetParameters.Platform)
+ .SetSelfContained(dotnetParameters.Portable)
+ .SetPublishSingleFile(false)
+ .SetPublishReadyToRun(false)
+ .SetPublishTrimmed(false)
+ .SetVerbosity(DotNetVerbosity.Quiet)
+ .SetProcessArgumentConfigurator(_ => _
+ .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
+ .Add("/p:Unpackaged=" + dotnetParameters.Portable)
+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
+ .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));
+ }
+ }
+
+ void PublishMacApp()
+ {
+ // DevToys MAUI Blazor Mac Catalyst
+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForMacOSApp())
+ {
+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
+ DotNetBuild(s => s
+ .SetProjectFile(dotnetParameters.ProjectOrSolutionPath)
+ .SetConfiguration(Configuration)
+ .SetSelfContained(true)
+ .SetPublishSingleFile(false) // Not supported by MacCatalyst as it would require UseAppHost to be true, which isn't supported on Mac
+ .SetPublishReadyToRun(false)
+ .SetPublishTrimmed(false)
+ .SetVerbosity(DotNetVerbosity.Quiet)
+ .SetNoRestore(true) /* workaround for https://github.com/xamarin/xamarin-macios/issues/15664#issuecomment-1233123515 */
+ .SetProcessArgumentConfigurator(_ => _
+ .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)
+ .Add("/p:CreatePackage=True") /* Will create an installable .pkg */
+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
+ .SetOutputDirectory(RootDirectory / "publish" / dotnetParameters.OutputPath));
+ }
+ }
+
+ void PublishCliApp()
+ {
+ // DevToys CLI
+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForCliApp())
+ {
+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");
+ DotNetPublish(s => s
+ .SetProject(dotnetParameters.ProjectOrSolutionPath)
+ .SetConfiguration(Configuration)
+ .SetFramework(dotnetParameters.TargetFramework)
+ .SetRuntime(dotnetParameters.RuntimeIdentifier)
+ .SetSelfContained(dotnetParameters.Portable)
+ .SetPublishSingleFile(dotnetParameters.Portable)
+ .SetPublishReadyToRun(false)
+ .SetPublishTrimmed(false)
+ .SetVerbosity(DotNetVerbosity.Quiet)
+ .SetProcessArgumentConfigurator(_ => _
+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))
+ .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));
+ }
+ }
+
IEnumerable<DotnetParameters> GetDotnetParametersForCliApp()
{
string publishProject = "DevToys.CLI";
@@ -292,12 +281,13 @@ class Build : NukeBuild
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// TODO
+ throw new NotSupportedException();
}
}
- IEnumerable<DotnetParameters> GetDotnetParametersForWasdkApp()
+ IEnumerable<DotnetParameters> GetDotnetParametersForWindowsApp()
{
- string publishProject = "DevToys.Wasdk";
+ string publishProject = "DevToys.Windows";
Project project;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -320,36 +310,6 @@ class Build : NukeBuild
}
}
- IEnumerable<DotnetParameters> GetDotnetParametersForMauiBlazorApp()
- {
- string publishProject = "DevToys.MacOS";
- Project project;
-
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {
- project = MacSolution!.GetProject(publishProject);
- foreach (string targetFramework in project.GetTargetFrameworks())
- {
- yield return new DotnetParameters(project.Path, "maccatalyst-arm64", targetFramework, portable: true);
- yield return new DotnetParameters(project.Path, "maccatalyst-x64", targetFramework, portable: true);
- }
- }
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- project = WindowsSolution!.GetProject(publishProject);
- foreach (string targetFramework in project.GetTargetFrameworks())
- {
- yield return new DotnetParameters(project.Path, "win10-arm64", targetFramework, portable: true);
- yield return new DotnetParameters(project.Path, "win10-x64", targetFramework, portable: true);
- yield return new DotnetParameters(project.Path, "win10-x86", targetFramework, portable: true);
- }
- }
- else
- {
- throw new NotSupportedException();
- }
- }
-
IEnumerable<DotnetParameters> GetDotnetParametersForMacOSApp()
{
string publishProject = "DevToys.MacOS";
@@ -364,16 +324,6 @@ class Build : NukeBuild
yield return new DotnetParameters(project.Path, "maccatalyst-x64", targetFramework, portable: true);
}
}
- else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- project = WindowsSolution!.GetProject(publishProject);
- foreach (string targetFramework in project.GetTargetFrameworks())
- {
- yield return new DotnetParameters(project.Path, "win10-arm64", targetFramework, portable: true);
- yield return new DotnetParameters(project.Path, "win10-x64", targetFramework, portable: true);
- yield return new DotnetParameters(project.Path, "win10-x86", targetFramework, portable: true);
- }
- }
else
{
throw new NotSupportedException();