wpf替换ico图标不生效
date: 2024/5/23
将 ICO 文件添加到项目:直接在vs项目目录下创建一个Img目录命名为favicon.ico
主窗口设置正确的图标路径
Icon="/Syncfiles;component/img/favicon.ico"
修改项目文件(.csproj)
方法1这样会将img文件都发布,没有Img文件夹不能运行
<ItemGroup>
<Content Include="img\favicon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
方法2,内嵌到程序,不需要img文件夹也能运行
<ItemGroup>
<Resource Include="img\favicon.ico" />
</ItemGroup>
发布命令
dotnet publish -c Release -r win-x64 --self-contained false