Skip to content

Instantly share code, notes, and snippets.

@luojunyuan
Last active July 4, 2026 09:06
Show Gist options
  • Select an option

  • Save luojunyuan/4efd1e363e324593379c40d8b695d916 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
Author


能跑的最小的 winui 应用,默认 dotnet publish 就能生成
生成出来 总共 42 个项目,比起 debug 版(dotnet build 版 / VS 生成版),少了俩 xbf 文件
Aot 编译出来的。。总共就4个dll,也是有些完全多余的dll
(Microsoft.Windows.ApplicationModel.Background.UniversalBGTask)
(WebView)
只有 Microsoft.WindowsAppRuntime.Bootstrap 这个好像有用
增加 -r 指定 rid 完全等于把里面的三个 dll 提到目录顶层来了

结论 AnyCPU WinUI 没有任何问题,注意去掉任何 framework dependency

WindowsAppSDKSelfContained 就是会有一大串 Microsoft 开头的 dll winmd

我不太确定以下是不是 wasdk 最小依赖,有可能因为我电脑上自带 wasdk runtime 所以这一串能运行

CoreMessagingXP.dll 
dcompi.dll 
dwmcorei.dll 
marshal.dll 
Microsoft.DirectManipulation.dll 
Microsoft.InputStateManager.dll 
Microsoft.Internal.FrameworkUdk.dll 
Microsoft.UI.Composition.OSSupport.dll 
Microsoft.UI.Input.dll 
Microsoft.UI.Windowing.Core.dll 
Microsoft.UI.Windowing.dll 
Microsoft.UI.Xaml.Controls.dll 
Microsoft.ui.xaml.dll 
Microsoft.UI.Xaml.Phone.dll 
Microsoft.ui.xaml.resources.19h1.dll 
Microsoft.Windows.ApplicationModel.Resources.dll 
Microsoft.WindowsAppRuntime.dll 
Microsoft.WindowsAppRuntime.Insights.Resource.dll 
MRM.dll 
wuceffectsi.dll

感觉还是不太一样,直接拷贝应该是不行的。
不知道dotnetbootstrap 感觉不会自动帮忙安装 wasdk 依赖
还是启动的时候会提示安装,如果是这样,那么这条路还是能走通

@luojunyuan

luojunyuan commented Jul 4, 2026

Copy link
Copy Markdown
Author

I hate wasdk

<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.2270" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.2.0" />
<PackageReference Include="Microsoft.WindowsAppSDK.AI" Version="2.2.3" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK.DWrite" Version="2.1.0" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.Windows.AI.MachineLearning" Version="2.1.70" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK.ML" Version="2.1.70" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.WindowsAppSDK.Widgets" Version="2.0.5" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3719.77" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="System.Numerics.Tensors" Version="9.0.0" ExcludeAssets="all" PrivateAssets="all" />

不能排除这个,会直接影响生成产物,生成带 i18n 文件夹一大坨,直接只引用 Microsoft.WindowsAppSDK.WinUI 也是同理。
Include="Microsoft.WindowsAppSDK.Runtime"

下面这样就没问题。。也就是说最新的 wasdk winui 依赖方式像下面一样

<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="2.2.1" />
<PackageReference Include="Microsoft.WindowsAppSDK.Runtime" Version="2.2.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4022.49" ExcludeAssets="all" PrivateAssets="all" />

如果依赖引用了低版本的 Microsoft.WindowsAppSDK 直接依赖就会报错,还是需要排除

<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.2.0" />    
<PackageReference Include="Microsoft.Windows.AI.MachineLearning" Version="2.1.70" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3719.77" ExcludeAssets="all" PrivateAssets="all" />

关键只需要 去掉 Microsoft.Windows.AI.MachineLearning 这个包就完美如初了

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