1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WinUi3をWPFの代わりに使う時いつもやってること。

Last updated at Posted at 2025-02-18

1.プロジェクト名.csprojファイルの修正

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>MyApp</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
    <PublishProfile>win-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
    <Nullable>enable</Nullable>
+    <WindowsPackageType>None</WindowsPackageType>
+    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>

-  <ItemGroup>
-    <Content Include="Assets\SplashScreen.scale-200.png" />
-    <Content Include="Assets\LockScreenLogo.scale-200.png" />
-    <Content Include="Assets\Square150x150Logo.scale-200.png" />
-    <Content Include="Assets\Square44x44Logo.scale-200.png" />
-    <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
-    <Content Include="Assets\StoreLogo.png" />
-    <Content Include="Assets\Wide310x150Logo.scale-200.png" />
-  </ItemGroup>

-  <ItemGroup>
-    <Manifest Include="$(ApplicationManifest)" />
-  </ItemGroup>

-  <!--
-    Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
-    Tools extension to be activated for this project even if the Windows App SDK Nuget
-    package has not yet been restored.
-  -->
-  <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
-    <ProjectCapability Include="Msix" />
-  </ItemGroup>
  <ItemGroup>
-    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
  </ItemGroup>

-  <!--
-    Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
-    Explorer "Package and Publish" context menu entry to be enabled for this project even if
-    the Windows App SDK Nuget package has not yet been restored.
-  -->
-  <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
-    <HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
-  </PropertyGroup>

-  <!-- Publish Properties -->
-  <PropertyGroup>
-    <PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
-    <PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
-    <PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
-    <PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
-  </PropertyGroup>
</Project>
メモ 自己完結型にしたくない場合はWindowsAppSDKSelfContained要素を追記する必要はないが自己完結型にしなければソリューションエクスプローラーに自動生成された一部ファイルが表示されてしまったりインストールされているランタイムとバージョンが異なる場合実行時にインストールを促すダイアログが表示されてしまったりするので個人的には自己完結型にすること推奨。

スクリーンショット (8).png

Microsoft.Windows.SDK.BuildToolsへのnuget参照はMicrosoft.WindowsAppSDKが参照しており、不要なので削除しているものの削除しなくても問題なく動く。

2.csprojファイルのプロパティからマニフェストファイル系の設定

プロジェクト名.csprojファイルを右クリックしてプロパティを選択後
アプリケーション => Win32リソース => マニフェスト内の項目を"マニフェストなしでアプリケーションを作成します"に指定する。

スクリーンショット (13).png

メモ この操作はプロジェクト名.cprojファイルにて

<NoWin32Manifest>true</NoWin32Manifest>

を追記する作業と同じであるはずだがなぜかこの要素を追加するだけでは反映されないのでわざわざGUIのプロパティ設定画面から操作する必要がある。
なんでだ...(汗)

3.不要なプロジェクト内のファイル/フォルダを削除

  • Propertiesフォルダ
  • Assetsフォルダ
  • app.manifestファイル
  • Package.appxmanifestファイル

上記プロジェクト内のファイル/フォルダを削除

スクリーンショット (11).png

4.試しにF5キーをクリックしてデバッグ実行してみる

これで実行出来たらWPFライクなWinUi3プロジェクトの作成に成功です。

スクリーンショット (12).png
この状態でのプロジェクト内のファイルは自作Appクラス用のxamlファイル+コードビハインドのcsファイルと自作Windowクラス用のxamlファイル+コードビハインドのcsファイルで計四つで、ソリューションエクスプローラーに表示されているファイル数は未展開でxamlファイルのみの2つです。
WPFプロジェクトの初期状態と同じような状態になってるはずです。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?