Skip to content

Instantly share code, notes, and snippets.

@luojunyuan
Last active May 22, 2025 03:48
Show Gist options
  • Save luojunyuan/4efd1e363e324593379c40d8b695d916 to your computer and use it in GitHub Desktop.
Save luojunyuan/4efd1e363e324593379c40d8b695d916 to your computer and use it in GitHub Desktop.
the minimal request csproj properties for creating an unpackage desktop winui app
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
<UseWinUI>true</UseWinUI>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<Platforms Condition="'$(WindowsAppSDKSelfContained)' == 'true'">x64;ARM64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250205002" />
<PackageReference Condition="'$(PublishAot)' == 'true'" Include="Microsoft.Web.WebView2" Version="1.0.3065.39" />
</ItemGroup>
</Project>
@luojunyuan
Copy link
Author

  1. 引用新版本的 WebView2 是为了避免 AOT 编译时发出的警告
  2. EnableMsixTooling 是为了启用 dotnet cli
  3. WindowsAppSDKSelfContained 设置为 false 会导致框架初始化设置同步上下文时 COMException: 没有注册类 0x80040154
  4. Platforms 是为了避免因 WindowsAppSDKSelfContained 引起的 VS 找不到架构的错误警告

@luojunyuan
Copy link
Author

要使用 dotnet cli build 需要指定架构如 -r win-x64

@luojunyuan
Copy link
Author

没有 launchSetting.json 的前提下 好像就需要 <WindowsPackageType>None</WindowsPackageType> 这个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment