Skip to content

Commit 8ae4895

Browse files
committed
New Template Project for WindowsAppSdk.
1 parent 3ed034f commit 8ae4895

File tree

90 files changed

+3196
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3196
-392
lines changed

.editorconfig

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Rules in this file were initially inferred by Visual Studio IntelliCode from the Template Studio codebase.
2+
# You can modify the rules from these initially generated values to suit your own policies.
3+
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference.
4+
5+
[*.cs]
6+
7+
#Core editorconfig formatting - indentation
8+
9+
#use soft tabs (spaces) for indentation
10+
indent_style = space
11+
12+
#Formatting - new line options
13+
14+
#place else statements on a new line
15+
csharp_new_line_before_else = true
16+
#require braces to be on a new line for lambdas, methods, control_blocks, types, properties, and accessors (also known as "Allman" style)
17+
csharp_new_line_before_open_brace = all
18+
19+
#Formatting - organize using options
20+
21+
#sort System.* using directives alphabetically, and place them before other usings
22+
dotnet_sort_system_directives_first = true
23+
24+
#Formatting - spacing options
25+
26+
#require NO space between a cast and the value
27+
csharp_space_after_cast = false
28+
#require a space before the colon for bases or interfaces in a type declaration
29+
csharp_space_after_colon_in_inheritance_clause = true
30+
#require a space after a keyword in a control flow statement such as a for loop
31+
csharp_space_after_keywords_in_control_flow_statements = true
32+
#require a space before the colon for bases or interfaces in a type declaration
33+
csharp_space_before_colon_in_inheritance_clause = true
34+
#remove space within empty argument list parentheses
35+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
36+
#remove space between method call name and opening parenthesis
37+
csharp_space_between_method_call_name_and_opening_parenthesis = false
38+
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
39+
csharp_space_between_method_call_parameter_list_parentheses = false
40+
#remove space within empty parameter list parentheses for a method declaration
41+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
42+
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
43+
csharp_space_between_method_declaration_parameter_list_parentheses = false
44+
45+
#Formatting - wrapping options
46+
47+
#leave code block on separate lines
48+
csharp_preserve_single_line_blocks = false
49+
50+
#Style - Code block preferences
51+
52+
#prefer curly braces even for one line of code
53+
csharp_prefer_braces = true:suggestion
54+
55+
#Style - expression bodied member options
56+
57+
#prefer expression bodies for accessors
58+
csharp_style_expression_bodied_accessors = true:warning
59+
#prefer block bodies for constructors
60+
csharp_style_expression_bodied_constructors = false:suggestion
61+
#prefer expression bodies for methods
62+
csharp_style_expression_bodied_methods = when_on_single_line:silent
63+
#prefer expression-bodied members for properties
64+
csharp_style_expression_bodied_properties = true:warning
65+
66+
#Style - expression level options
67+
68+
#prefer out variables to be declared before the method call
69+
csharp_style_inlined_variable_declaration = false:suggestion
70+
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
71+
dotnet_style_predefined_type_for_member_access = true:suggestion
72+
73+
#Style - Expression-level preferences
74+
75+
#prefer default over default(T)
76+
csharp_prefer_simple_default_expression = true:suggestion
77+
#prefer objects to be initialized using object initializers when possible
78+
dotnet_style_object_initializer = true:suggestion
79+
80+
#Style - implicit and explicit types
81+
82+
#prefer var over explicit type in all cases, unless overridden by another code style rule
83+
csharp_style_var_elsewhere = true:suggestion
84+
#prefer var is used to declare variables with built-in system types such as int
85+
csharp_style_var_for_built_in_types = true:suggestion
86+
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
87+
csharp_style_var_when_type_is_apparent = true:suggestion
88+
89+
#Style - language keyword and framework type options
90+
91+
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
92+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
93+
94+
#Style - Language rules
95+
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
96+
csharp_style_var_for_built_in_types = true:warning
97+
98+
#Style - modifier options
99+
100+
#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
101+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
102+
103+
#Style - Modifier preferences
104+
105+
#when this rule is set to a list of modifiers, prefer the specified ordering.
106+
csharp_preferred_modifier_order = public,private,protected,internal,static,async,readonly,override,sealed,abstract,virtual:warning
107+
dotnet_style_readonly_field = true:warning
108+
109+
#Style - Pattern matching
110+
111+
#prefer pattern matching instead of is expression with type casts
112+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
113+
114+
#Style - qualification options
115+
116+
#prefer events not to be prefaced with this. or Me. in Visual Basic
117+
dotnet_style_qualification_for_event = false:suggestion
118+
#prefer fields not to be prefaced with this. or Me. in Visual Basic
119+
dotnet_style_qualification_for_field = false:suggestion
120+
#prefer methods not to be prefaced with this. or Me. in Visual Basic
121+
dotnet_style_qualification_for_method = false:suggestion
122+
#prefer properties not to be prefaced with this. or Me. in Visual Basic
123+
dotnet_style_qualification_for_property = false:suggestion
124+
csharp_indent_labels = one_less_than_current
125+
csharp_using_directive_placement = outside_namespace:silent
126+
csharp_prefer_simple_using_statement = true:warning
127+
csharp_style_namespace_declarations = file_scoped:warning
128+
csharp_style_expression_bodied_operators = false:silent
129+
csharp_style_expression_bodied_indexers = true:silent
130+
csharp_style_expression_bodied_lambdas = true:silent
131+
csharp_style_expression_bodied_local_functions = false:silent
132+
133+
[*.{cs,vb}]
134+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
135+
tab_width = 4
136+
indent_size = 4
137+
end_of_line = crlf
138+
dotnet_style_coalesce_expression = true:suggestion
139+
dotnet_style_null_propagation = true:suggestion
140+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
141+
dotnet_style_prefer_auto_properties = true:silent
142+
dotnet_style_object_initializer = true:suggestion
143+
dotnet_style_collection_initializer = true:suggestion
144+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
145+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
146+
dotnet_style_prefer_conditional_expression_over_return = true:silent
147+
[*.{cs,vb}]
148+
149+
#Style - Unnecessary code rules
150+
csharp_style_unused_value_assignment_preference = discard_variable:warning
151+
152+
#### Naming styles ####
153+
154+
# Naming rules
155+
156+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
157+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
158+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
159+
160+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
161+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
162+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
163+
164+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
165+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
166+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
167+
168+
# Symbol specifications
169+
170+
dotnet_naming_symbols.interface.applicable_kinds = interface
171+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
172+
dotnet_naming_symbols.interface.required_modifiers =
173+
174+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
175+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
176+
dotnet_naming_symbols.types.required_modifiers =
177+
178+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
179+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
180+
dotnet_naming_symbols.non_field_members.required_modifiers =
181+
182+
# Naming styles
183+
184+
dotnet_naming_style.begins_with_i.required_prefix = I
185+
dotnet_naming_style.begins_with_i.required_suffix =
186+
dotnet_naming_style.begins_with_i.word_separator =
187+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
188+
189+
dotnet_naming_style.pascal_case.required_prefix =
190+
dotnet_naming_style.pascal_case.required_suffix =
191+
dotnet_naming_style.pascal_case.word_separator =
192+
dotnet_naming_style.pascal_case.capitalization = pascal_case
193+
194+
dotnet_naming_style.pascal_case.required_prefix =
195+
dotnet_naming_style.pascal_case.required_suffix =
196+
dotnet_naming_style.pascal_case.word_separator =
197+
dotnet_naming_style.pascal_case.capitalization = pascal_case
198+
dotnet_style_explicit_tuple_names = true:suggestion
199+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
200+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
201+
dotnet_style_prefer_compound_assignment = true:warning
202+
dotnet_style_prefer_simplified_interpolation = true:suggestion

.vsconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "1.0",
3+
"components": [
4+
"Microsoft.Component.MSBuild",
5+
"Microsoft.NetCore.Component.Runtime.6.0",
6+
"Microsoft.NetCore.Component.SDK",
7+
"Microsoft.VisualStudio.Component.ManagedDesktop.Core",
8+
"Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
9+
"Microsoft.VisualStudio.Component.NuGet",
10+
"Microsoft.VisualStudio.Component.Windows10SDK.19041",
11+
"Microsoft.VisualStudio.Component.Windows10SDK",
12+
"Microsoft.VisualStudio.ComponentGroup.MSIX.Packaging",
13+
"Microsoft.VisualStudio.ComponentGroup.WindowsAppSDK.Cs",
14+
"Microsoft.VisualStudio.Workload.ManagedDesktop"
15+
]
16+
}

WindowsAppSdkHost.sln

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,86 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Extensions
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{59093D20-3B21-11EC-BDE7-AF52EAA7DCFD}"
1111
EndProject
12-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedWindowsAppSdk", "templates\HostedWindowsAppSdk\HostedWindowsAppSdk.csproj", "{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompleteWithInstaller", "templates\CompleteWithInstaller\CompleteWithInstaller.csproj", "{8183D194-CF46-48F8-A054-5F09E2DA69B8}"
1313
EndProject
14-
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "HostedWindowsAppSdk.Installer", "templates\HostedWindowsAppSdk.Installer\HostedWindowsAppSdk.Installer.wapproj", "{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompleteWithInstaller.Core", "templates\CompleteWithInstaller.Core\CompleteWithInstaller.Core.csproj", "{C272842D-E647-45A9-AB72-A96623C84B6B}"
1515
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Debug|ARM64 = Debug|ARM64
1820
Debug|x64 = Debug|x64
21+
Debug|x86 = Debug|x86
22+
Release|Any CPU = Release|Any CPU
23+
Release|ARM64 = Release|ARM64
1924
Release|x64 = Release|x64
25+
Release|x86 = Release|x86
2026
EndGlobalSection
2127
GlobalSection(ProjectConfigurationPlatforms) = postSolution
28+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|Any CPU.ActiveCfg = Debug|x64
29+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|Any CPU.Build.0 = Debug|x64
30+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|ARM64.ActiveCfg = Debug|ARM64
31+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|ARM64.Build.0 = Debug|ARM64
2232
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|x64.ActiveCfg = Debug|x64
2333
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|x64.Build.0 = Debug|x64
34+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|x86.ActiveCfg = Debug|x86
35+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Debug|x86.Build.0 = Debug|x86
36+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|Any CPU.ActiveCfg = Release|x64
37+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|Any CPU.Build.0 = Release|x64
38+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|ARM64.ActiveCfg = Release|ARM64
39+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|ARM64.Build.0 = Release|ARM64
2440
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|x64.ActiveCfg = Release|x64
2541
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|x64.Build.0 = Release|x64
26-
{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7}.Debug|x64.ActiveCfg = Debug|x64
27-
{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7}.Debug|x64.Build.0 = Debug|x64
28-
{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7}.Release|x64.ActiveCfg = Release|x64
29-
{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7}.Release|x64.Build.0 = Release|x64
30-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Debug|x64.ActiveCfg = Debug|x64
31-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Debug|x64.Build.0 = Debug|x64
32-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Debug|x64.Deploy.0 = Debug|x64
33-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Release|x64.ActiveCfg = Release|x64
34-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Release|x64.Build.0 = Release|x64
35-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011}.Release|x64.Deploy.0 = Release|x64
42+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|x86.ActiveCfg = Release|x86
43+
{624647A5-F444-43BE-82CD-3C38ECA17BD9}.Release|x86.Build.0 = Release|x86
44+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|Any CPU.ActiveCfg = Debug|x64
45+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|Any CPU.Build.0 = Debug|x64
46+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|Any CPU.Deploy.0 = Debug|x64
47+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|ARM64.ActiveCfg = Debug|arm64
48+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|ARM64.Build.0 = Debug|arm64
49+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|ARM64.Deploy.0 = Debug|arm64
50+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x64.ActiveCfg = Debug|x64
51+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x64.Build.0 = Debug|x64
52+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x64.Deploy.0 = Debug|x64
53+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x86.ActiveCfg = Debug|x86
54+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x86.Build.0 = Debug|x86
55+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Debug|x86.Deploy.0 = Debug|x86
56+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|Any CPU.ActiveCfg = Release|x64
57+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|Any CPU.Build.0 = Release|x64
58+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|Any CPU.Deploy.0 = Release|x64
59+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|ARM64.ActiveCfg = Release|arm64
60+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|ARM64.Build.0 = Release|arm64
61+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|ARM64.Deploy.0 = Release|arm64
62+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x64.ActiveCfg = Release|x64
63+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x64.Build.0 = Release|x64
64+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x64.Deploy.0 = Release|x64
65+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x86.ActiveCfg = Release|x86
66+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x86.Build.0 = Release|x86
67+
{8183D194-CF46-48F8-A054-5F09E2DA69B8}.Release|x86.Deploy.0 = Release|x86
68+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|Any CPU.ActiveCfg = Debug|x64
69+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|Any CPU.Build.0 = Debug|x64
70+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|ARM64.ActiveCfg = Debug|arm64
71+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|ARM64.Build.0 = Debug|arm64
72+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|x64.ActiveCfg = Debug|x64
73+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|x64.Build.0 = Debug|x64
74+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|x86.ActiveCfg = Debug|x86
75+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Debug|x86.Build.0 = Debug|x86
76+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|Any CPU.ActiveCfg = Release|x64
77+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|Any CPU.Build.0 = Release|x64
78+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|ARM64.ActiveCfg = Release|arm64
79+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|ARM64.Build.0 = Release|arm64
80+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|x64.ActiveCfg = Release|x64
81+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|x64.Build.0 = Release|x64
82+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|x86.ActiveCfg = Release|x86
83+
{C272842D-E647-45A9-AB72-A96623C84B6B}.Release|x86.Build.0 = Release|x86
3684
EndGlobalSection
3785
GlobalSection(SolutionProperties) = preSolution
3886
HideSolutionNode = FALSE
3987
EndGlobalSection
4088
GlobalSection(NestedProjects) = preSolution
4189
{624647A5-F444-43BE-82CD-3C38ECA17BD9} = {866D1621-C2C8-4F68-A928-D6EE9D25E335}
42-
{2A3F2AE1-302E-4BB0-9B5F-6B4F9B20CBF7} = {59093D20-3B21-11EC-BDE7-AF52EAA7DCFD}
43-
{AFC3E846-1DE5-409C-ACB5-A0C0281DA011} = {59093D20-3B21-11EC-BDE7-AF52EAA7DCFD}
90+
{8183D194-CF46-48F8-A054-5F09E2DA69B8} = {59093D20-3B21-11EC-BDE7-AF52EAA7DCFD}
91+
{C272842D-E647-45A9-AB72-A96623C84B6B} = {59093D20-3B21-11EC-BDE7-AF52EAA7DCFD}
4492
EndGlobalSection
4593
GlobalSection(ExtensibilityGlobals) = postSolution
4694
SolutionGuid = {EDC7A06A-AD43-4918-B9B9-5836FEE0AE33}

docs/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Windows App SDK Host
2+
3+
Allows hosting a Windows App SDK Application in an `IHost` that manages the lifecycle of the hosted Application.
4+
5+
[![Packages](https://github.com/sharpninja/WindowsAppSdkHost/actions/workflows/packages.yml/badge.svg)](https://github.com/sharpninja/WindowsAppSdkHost/actions/workflows/packages.yml)
6+
7+
## Usage
8+
9+
__(Convert existing project or the default template's output)__
10+
11+
1. Add `<DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>` in the main `PropertyGroup` of your applications project file.
12+
2. Add reference to `CommunityToolkit.Extensions.Hosting.WindowsAppSdk`
13+
3. Add `Program.cs` to the root of your application project.
14+
4. Add this code to the `Program.cs`:
15+
16+
```csharp
17+
public static class Program
18+
{
19+
[STAThread]
20+
public static void Main(string[] args)
21+
{
22+
var builder = new WindowsAppSdkHostBuilder<App>();
23+
24+
builder.ConfigureServices(
25+
(_, collection) =>
26+
{
27+
// If your main Window is named differently, change it here.
28+
collection.AddSingleton<MainWindow>();
29+
}
30+
);
31+
32+
var app = builder.Build();
33+
34+
app.StartAsync().GetAwaiter().GetResult();
35+
}
36+
}
37+
```
38+
39+
5. Set your `Program.cs` as the startup object by adding `<StartupObject>HostedWindowsAppSdk.Program</StartupObject>` to your project file.
40+
6. Use the `CancelableApplication` as the base class of your application by modifying your `App.xaml`:
41+
42+
```xml
43+
<host:CancelableApplication
44+
x:Class="HostedWindowsAppSdk.App"
45+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
46+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
47+
xmlns:host="using:CommunityToolkit.Extensions.Hosting"
48+
xmlns:local="using:HostedWindowsAppSdk">
49+
<Application.Resources>
50+
</Application.Resources>
51+
</host:CancelableApplication>
52+
```
53+
54+
7. Update your App.xaml.cs to use dependency injection.
55+
56+
```csharp
57+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
58+
{
59+
// Get window from Dependency Injection.
60+
_mWindow = Services.GetRequiredService<MainWindow>();
61+
62+
63+
_mWindow.Activate();
64+
}
65+
```
66+
67+
## Notes
68+
69+
The `WindowsAppSdkHost` uses several features of the Microsoft.Extensions ecosystem:
70+
71+
1. Includes all configuration resources defined for the `DefaultHostBuilder`.
72+
2. Registers the required `CancellableApplication` with dependency injection.
73+
3. Manages the lifecycle of the Application in the `StartAsync` method of the `WindowsAppSdkHost`.
74+
4. Write unhandled errors to default `ILogger`. The `Ilogger` can be obtained from the static `Services` property of the `CancellableApplication` after building the app.
75+
76+
If there are other patterns you feel should be available or required then start a discussion.

0 commit comments

Comments
 (0)