やりたいこと
WinUI3で作成したアプリを、スタートアップで起動するようにしたい。
サンプルコード(Package.appxmanifest)
Package.appxmanifest
に、下記を行う。
<Package>
の先頭に、xmlns:desktop=・・・
の1行を追加するIgnorableNamespaces
に、desktopを追加する
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" ★←コレと IgnorableNamespaces="uap rescap desktop"> ★←ここのdesktopを、半角スペースを空けて追記
次に、<Application>
の中に、下記を追記する。
<Extensions> <desktop:Extension Category="windows.startupTask" ★windows.startupTaskを指定すると、スタートアップのexeを指定したことになる Executable="WinUI3PJTest\WinUI3PJTest.exe" ★ここが、動いてほしいexeのパス EntryPoint="Windows.FullTrustApplication"> ★これはおまじない <desktop:StartupTask TaskId="MyStartupTask" ★TaskIdは任意で Enabled="true" DisplayName="My App Service" /> </desktop:Extension> </Extensions>
上記を追記したPackage.appxmanifest
全体は下記の通り。
<?xml version="1.0" encoding="utf-8"?> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" IgnorableNamespaces="uap rescap desktop"> <Identity Name="06bf9954-f1d3-4269-b9ff-078b5e4fae1d" Publisher="CN=masa" Version="1.0.0.0" /> <Properties> <DisplayName>WinUI3PJTest (Package)</DisplayName> <PublisherDisplayName>masa</PublisherDisplayName> <Logo>Images\StoreLogo.png</Logo> </Properties> <Dependencies> <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" /> <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" /> </Dependencies> <Resources> <Resource Language="x-generate"/> </Resources> <Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$"> <uap:VisualElements DisplayName="WinUI3PJTest (Package)" Description="WinUI3PJTest (Package)" BackgroundColor="transparent" Square150x150Logo="Images\Square150x150Logo.png" Square44x44Logo="Images\Square44x44Logo.png"> <uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" /> <uap:SplashScreen Image="Images\SplashScreen.png" /> </uap:VisualElements> <Extensions> <desktop:Extension Category="windows.startupTask" Executable="WinUI3PJTest\WinUI3PJTest.exe" EntryPoint="Windows.FullTrustApplication"> <desktop:StartupTask TaskId="MyStartupTask" Enabled="true" DisplayName="My App Service" /> </desktop:Extension> </Extensions> </Application> </Applications> <Capabilities> <rescap:Capability Name="runFullTrust" /> </Capabilities> </Package>
参考
ここに公式サンプルあり。