Skip to content

Commit

Permalink
Merge pull request #131 from AvaloniaUI/update-templates
Browse files Browse the repository at this point in the history
Update templates
  • Loading branch information
maxkatz6 authored Nov 15, 2022
2 parents c15e0cc + 32cedf8 commit cb9c51a
Show file tree
Hide file tree
Showing 75 changed files with 604 additions and 635 deletions.
2 changes: 1 addition & 1 deletion Avalonia.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>0.10.18.1</PackageVersion>
<PackageVersion>0.10.18.2</PackageVersion>
<PackageId>Avalonia.Templates</PackageId>
<Title>Avalonia Templates</Title>
<Description>Templates for creating Avalonia applications and libraries.</Description>
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ steps:
- task: CmdLine@2
displayName: 'Install templates'
inputs:
script: 'dotnet new -i $(Build.ArtifactStagingDirectory)/NuGet/*.nupkg'
script: 'dotnet new install $(Build.ArtifactStagingDirectory)/NuGet/*.nupkg'
- task: CmdLine@2
displayName: 'Install WASM workload'
displayName: 'Install workload'
inputs:
script: 'dotnet workload install --no-cache --disable-parallel ios android wasm-tools wasm-experimental'
- task: PowerShell@2
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Available parameters:

*Description*: The target version of Avalonia NuGet packages.

*Options*: **0.10.18**, **11.0.0-preview3**
*Options*: **0.10.18**, **11.0.0-preview4**

*By default*: 0.10.18

Expand Down
35 changes: 17 additions & 18 deletions templates/csharp/app-mvvm/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
using AvaloniaAppTemplate.ViewModels;
using AvaloniaAppTemplate.Views;

namespace AvaloniaAppTemplate
namespace AvaloniaAppTemplate;

public partial class App : Application
{
public partial class App : Application
public override void Initialize()
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
desktop.MainWindow = new MainWindow
{
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
12 changes: 5 additions & 7 deletions templates/csharp/app-mvvm/AvaloniaAppTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
<None Remove=".gitignore" />
</ItemGroup>

<ItemGroup>
<!--This helps with theme dll-s trimming.
If you will publish your application in self-contained mode with p:PublishTrimmed=true and it will use Fluent theme Default theme will be trimmed from the output and vice versa.
https://github.com/AvaloniaUI/Avalonia/issues/5593 -->
<TrimmableAssembly Include="Avalonia.Themes.Fluent" />
<TrimmableAssembly Include="Avalonia.Themes.Default" />
<TrimmerRootDescriptor Include="Roots.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.18" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
Expand Down
33 changes: 16 additions & 17 deletions templates/csharp/app-mvvm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
#endif
using System;

namespace AvaloniaAppTemplate
namespace AvaloniaAppTemplate;

class Program
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
#if (!ReactiveUIToolkitChosen)
.LogToTrace();
.LogToTrace();
#else
.LogToTrace()
.UseReactiveUI();
.LogToTrace()
.UseReactiveUI();
#endif
}
}
5 changes: 5 additions & 0 deletions templates/csharp/app-mvvm/Roots.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<linker>
<!-- Can be removed if CompiledBinding and no reflection are used -->
<assembly fullname="AvaloniaAppTemplate" preserve="All" />
<assembly fullname="Avalonia.Themes.Fluent" preserve="All" />
</linker>
33 changes: 16 additions & 17 deletions templates/csharp/app-mvvm/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,30 @@
using AvaloniaAppTemplate.ViewModels;
#endif

namespace AvaloniaAppTemplate
namespace AvaloniaAppTemplate;

public class ViewLocator : IDataTemplate
{
public class ViewLocator : IDataTemplate
public IControl Build(object data)
{
public IControl Build(object data)
{
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}

return new TextBlock { Text = "Not Found: " + name };
if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}

return new TextBlock { Text = "Not Found: " + name };
}

public bool Match(object data)
{
public bool Match(object data)
{

#if (ReactiveUIToolkitChosen)
return data is ViewModelBase;
return data is ViewModelBase;
#else
return data is INotifyPropertyChanged;
return data is INotifyPropertyChanged;
#endif
}
}
}
14 changes: 7 additions & 7 deletions templates/csharp/app-mvvm/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#if (!ReactiveUIToolkitChosen)
using CommunityToolkit.Mvvm.ComponentModel;
#endif
namespace AvaloniaAppTemplate.ViewModels
{

namespace AvaloniaAppTemplate.ViewModels;

#if (!ReactiveUIToolkitChosen)
public class MainWindowViewModel : ObservableObject
public class MainWindowViewModel : ObservableObject
#else
public class MainWindowViewModel : ViewModelBase
public class MainWindowViewModel : ViewModelBase
#endif
{
public string Greeting => "Welcome to Avalonia!";
}
{
public string Greeting => "Welcome to Avalonia!";
}
7 changes: 3 additions & 4 deletions templates/csharp/app-mvvm/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using ReactiveUI;

namespace AvaloniaAppTemplate.ViewModels
namespace AvaloniaAppTemplate.ViewModels;

public class ViewModelBase : ReactiveObject
{
public class ViewModelBase : ReactiveObject
{
}
}
11 changes: 5 additions & 6 deletions templates/csharp/app-mvvm/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Avalonia.Controls;

namespace AvaloniaAppTemplate.Views
namespace AvaloniaAppTemplate.Views;

public partial class MainWindow : Window
{
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
InitializeComponent();
}
InitializeComponent();
}
}
18 changes: 18 additions & 0 deletions templates/csharp/app-mvvm/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embeded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.Desktop"/>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
4 changes: 2 additions & 2 deletions templates/csharp/app/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"description": "Target 0.10.18 (Latest stable)."
},
{
"choice": "11.0.0-preview3",
"description": "Target 11.0.0-preview3"
"choice": "11.0.0-preview4",
"description": "Target 11.0.0-preview4"
}
],
"defaultValue": "0.10.18"
Expand Down
25 changes: 12 additions & 13 deletions templates/csharp/app/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace AvaloniaAppTemplate
namespace AvaloniaAppTemplate;

public partial class App : Application
{
public partial class App : Application
public override void Initialize()
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}

base.OnFrameworkInitializationCompleted();
desktop.MainWindow = new MainWindow();
}

base.OnFrameworkInitializationCompleted();
}
}
19 changes: 8 additions & 11 deletions templates/csharp/app/AvaloniaAppTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,29 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
</ItemGroup>

<ItemGroup>
<!--This helps with theme dll-s trimming.
If you will publish your application in self-contained mode with p:PublishTrimmed=true and it will use Fluent theme Default theme will be trimmed from the output and vice versa.
https://github.com/AvaloniaUI/Avalonia/issues/5593 -->
<TrimmableAssembly Include="Avalonia.Themes.Fluent" />
<TrimmableAssembly Include="Avalonia.Themes.Default" />
<TrimmerRootDescriptor Include="Roots.xml" />
</ItemGroup>

<ItemGroup>
<!--#if (AvaloniaStableChosen) -->
<PackageReference Include="Avalonia" Version="0.10.18" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" />
<!--#else-->
<PackageReference Include="Avalonia" Version="11.0.0-preview3" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview3" />
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview4" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview3" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />
<!--#endif -->
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
Expand Down
11 changes: 5 additions & 6 deletions templates/csharp/app/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Avalonia.Controls;

namespace AvaloniaAppTemplate
namespace AvaloniaAppTemplate;

public partial class MainWindow : Window
{
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
InitializeComponent();
}
InitializeComponent();
}
}
Loading

0 comments on commit cb9c51a

Please sign in to comment.