SharpNinja.Extensions.WindowsAppSdkHost
1.0.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SharpNinja.Extensions.WindowsAppSdkHost --version 1.0.7
NuGet\Install-Package SharpNinja.Extensions.WindowsAppSdkHost -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpNinja.Extensions.WindowsAppSdkHost" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpNinja.Extensions.WindowsAppSdkHost" Version="1.0.7" />
<PackageReference Include="SharpNinja.Extensions.WindowsAppSdkHost" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpNinja.Extensions.WindowsAppSdkHost --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SharpNinja.Extensions.WindowsAppSdkHost, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SharpNinja.Extensions.WindowsAppSdkHost@1.0.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpNinja.Extensions.WindowsAppSdkHost&version=1.0.7
#tool nuget:?package=SharpNinja.Extensions.WindowsAppSdkHost&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Windows App SDK Host
Allows hosting a Windows App SDK Application in an IHost that manages the lifecycle of the hosted Application.
Usage
(Convert existing project or the default template's output)
- Add
<DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>in the mainPropertyGroupof your applications project file. - Add reference to
CommunityToolkit.Extensions.Hosting.WindowsAppSdk - Add
Program.csto the root of your application project. - Add this code to the
Program.cs:
public static class Program
{
[STAThread]
public static void Main(string[] args)
{
var builder = new WindowsAppSdkHostBuilder<App>();
builder.ConfigureServices(
(_, collection) =>
{
// If your main Window is named differently, change it here.
collection.AddSingleton<MainWindow>();
}
);
var app = builder.Build();
app.StartAsync().GetAwaiter().GetResult();
}
}
- Set your
Program.csas the startup object by adding<StartupObject>HostedWindowsAppSdk.Program</StartupObject>to your project file. - Use the
CancelableApplicationas the base class of your application by modifying yourApp.xaml:
<host:CancelableApplication
x:Class="HostedWindowsAppSdk.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:host="using:CommunityToolkit.Extensions.Hosting"
xmlns:local="using:HostedWindowsAppSdk">
<Application.Resources>
</Application.Resources>
</host:CancelableApplication>
- Update your App.xaml.cs to use dependency injection.
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
// Get window from Dependency Injection.
_mWindow = Services.GetRequiredService<MainWindow>();
_mWindow.Activate();
}
Notes
The WindowsAppSdkHost uses several features of the Microsoft.Extensions ecosystem:
- Includes all configuration resources defined for the
DefaultHostBuilder. - Registers the required
CancellableApplicationwith dependency injection. - Manages the lifecycle of the Application in the
StartAsyncmethod of theWindowsAppSdkHost. - Write unhandled errors to default
ILogger. TheIloggercan be obtained from the staticServicesproperty of theCancellableApplicationafter building the app.
If there are other patterns you feel should be available or required then start a discussion.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0-windows10.0.19041 is compatible. net6.0-windows was computed. net6.0-windows10.0.19041 is compatible. net7.0-windows was computed. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0-windows10.0.19041
- Microsoft.Extensions.Hosting (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.WindowsAppSDK (>= 1.0.0)
-
net6.0-windows10.0.19041
- Microsoft.Extensions.Hosting (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.WindowsAppSDK (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.