在 Visual Studio 中,有没有办法根据构建配置更改应用程序图标? [英] In Visual Studio is there a way to change the Application Icon based on the build configuration?
问题描述
我工作的地方有一个我们公司使用的程序.然后,我们使用不同的数据和不同的背景、标题文本等构建同一程序的另一个版本.这一切都很好,但由于两者在技术上是相同的应用程序,因此两者的应用程序图标是相同的.我们希望每个构建都有单独的图标.
Where I work we have a program that is used by our company. We then have another build of that same program that uses different data and different backgrounds, title text, etc. This all works fine, but since both are technically the same application the Application Icon is the same for both. We want separate icons for each build.
在项目文件中设置Application图标:
The Application icon is set in the project file: <ApplicationIcon>MyIcon.ico</ApplicationIcon>
有没有办法根据构建配置使用不同的图标?我知道 Condition
属性对
标签无效.
Is there a way to have a different icon based on the build configuration? I know that the Condition
attribute is not valid for the <ApplicationIcon>
tag.
推荐答案
我知道 Condition 属性对于标签.
I know that the Condition attribute is not valid for the tag.
不,你没有.注意父
No you don't. Notice the parent <PropertyGroup /> tag? This indicates the ApplicationIcon tag is an MsBuild property so the Condition attribute would be valid in this case.
<PropertyGroup>
<ApplicationIcon Condition=" '$(Platform)' == 'x86' ">x86.ico</ApplicationIcon>
<ApplicationIcon Condition=" '$(Platform)' == 'x64' ">x64.ico</ApplicationIcon>
</PropertyGroup>
哎呀,如果您的文件名像上面那样解析为 MsBuild 属性值,您可以像这样推断文件名:
Heck, if your file names resolve to an MsBuild property value like they do above, you could infer the file name like so:
<PropertyGroup>
<ApplicationIcon>$(Platform).ico</ApplicationIcon>
</PropertyGroup>
假装上述用途并正确评估 $(Configuration) 属性值而不是 $(Platform)
Pretend the above uses and properly evaluates $(Configuration) property values rather than $(Platform)
这篇关于在 Visual Studio 中,有没有办法根据构建配置更改应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!