Browse Source

Move AppBuilder.UsePlatformDetect into Avalonia.Desktop and renamed the reflection-based one to a different name. Conditionalize the output-path loading like before.

Jeremy Koritzinsky 7 years ago
parent
commit
237f01fb1a

+ 1 - 1
Avalonia.sln

@@ -193,7 +193,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{E8
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia", "packages\Avalonia\Avalonia.csproj", "{D49233F8-F29C-47DD-9975-C4C9E4502720}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Desktop", "packages\Avalonia.Desktop\Avalonia.Desktop.csproj", "{3C471044-3640-45E3-B1B2-16D2FF8399EE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Desktop", "src\Avalonia.Desktop\Avalonia.Desktop.csproj", "{3C471044-3640-45E3-B1B2-16D2FF8399EE}"
 EndProject
 Global
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution

+ 1 - 1
build/SampleApp.props

@@ -3,6 +3,6 @@
     <OutputType>WinExe</OutputType>
   </PropertyGroup>
   <ItemGroup>
-    <ProjectReference Include="$(MSBuildThisFileDirectory)..\packages\Avalonia.Desktop\Avalonia.Desktop.csproj" />
+    <ProjectReference Include="$(MSBuildThisFileDirectory)..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />
   </ItemGroup>
 </Project>

+ 1 - 1
samples/ControlCatalog.NetCore/ControlCatalog.NetCore.csproj

@@ -8,7 +8,7 @@
   <ItemGroup>
     <ProjectReference Include="..\..\src\Linux\Avalonia.LinuxFramebuffer\Avalonia.LinuxFramebuffer.csproj" />
     <ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" />
-    <ProjectReference Include="..\..\packages\Avalonia.Desktop\Avalonia.Desktop.csproj" />
+    <ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />
   </ItemGroup>
 
 

+ 57 - 0
src/Avalonia.Desktop/AppBuilderDesktopExtensions.cs

@@ -0,0 +1,57 @@
+using Avalonia.Controls;
+using Avalonia.Platform;
+
+namespace Avalonia
+{
+    public static class AppBuilderDesktopExtensions
+    {
+        public static TAppBuilder UsePlatformDetect<TAppBuilder>(this TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+        {
+            var os = builder.RuntimePlatform.GetRuntimeInfo().OperatingSystem;
+
+            // We don't have the ability to load every assembly right now, so we are
+            // stuck with manual configuration  here
+            // Helpers are extracted to separate methods to take the advantage of the fact
+            // that CLR doesn't try to load dependencies before referencing method is jitted
+            // Additionally, by having a hard reference to each assembly,
+            // we verify that the assemblies are in the final .deps.json file
+            //  so .NET Core knows where to load the assemblies from,.
+            if (os == OperatingSystemType.WinNT)
+            {
+                LoadWin32(builder);
+                LoadDirect2D1(builder);
+            }
+            else if(os==OperatingSystemType.OSX)
+            {
+                LoadMonoMac(builder);
+                LoadSkia(builder);
+            }
+            else
+            {
+                LoadGtk3(builder);
+                LoadSkia(builder);
+            }
+            return builder;
+        }
+
+        static void LoadMonoMac<TAppBuilder>(TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+             => builder.UseMonoMac();
+        static void LoadWin32<TAppBuilder>(TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+             => builder.UseWin32();
+
+        static void LoadGtk3<TAppBuilder>(TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+             => builder.UseGtk3();
+
+        static void LoadDirect2D1<TAppBuilder>(TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+             => builder.UseDirect2D1();
+
+        static void LoadSkia<TAppBuilder>(TAppBuilder builder)
+            where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
+             => builder.UseSkia();
+    }
+}

+ 1 - 0
packages/Avalonia.Desktop/Avalonia.Desktop.csproj → src/Avalonia.Desktop/Avalonia.Desktop.csproj

@@ -9,5 +9,6 @@
       <ProjectReference Include="../../src/Skia/Avalonia.Skia/Avalonia.Skia.csproj" />
       <ProjectReference Include="../../src/Gtk/Avalonia.Gtk3/Avalonia.Gtk3.csproj" />
       <ProjectReference Include="../../src/OSX/Avalonia.MonoMac/Avalonia.MonoMac.csproj" />
+      <ProjectReference Include="../../packages/Avalonia/Avalonia.csproj" />
   </ItemGroup>
 </Project>

+ 1 - 1
src/Avalonia.DesktopRuntime/AppBuilder.cs

@@ -49,7 +49,7 @@ namespace Avalonia
         /// Instructs the <see cref="AppBuilder"/> to use the best settings for the platform.
         /// </summary>
         /// <returns>An <see cref="AppBuilder"/> instance.</returns>
-        public AppBuilder UsePlatformDetect()
+        public AppBuilder UseSubsystemsFromStartupDirectory()
         {
             var os = RuntimePlatform.GetRuntimeInfo().OperatingSystem;
 

+ 4 - 0
src/tools/Avalonia.Designer.HostApp/Program.cs

@@ -6,6 +6,7 @@ namespace Avalonia.Designer.HostApp
 {
     class Program
     {
+#if NET461
         private static string s_appDir;
         
         private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
@@ -35,6 +36,9 @@ namespace Avalonia.Designer.HostApp
         }
 
         static void Exec(string[] args)
+#else
+        public static void Main(string[] args)
+#endif
         {
             Avalonia.DesignerSupport.Remote.RemoteDesignerEntryPoint.Main(args);
         }

+ 1 - 1
tests/Avalonia.DesignerSupport.TestApp/Avalonia.DesignerSupport.TestApp.csproj

@@ -28,7 +28,7 @@
     <ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" />
     <ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" />
     <ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" />
-    <ProjectReference Include="..\..\packages\Avalonia.Desktop\Avalonia.Desktop.csproj" />
+    <ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />
   </ItemGroup>
   
   <Import Project="..\..\build\Serilog.props" />