In Visual Studio is there a way to change the Appl

2019-07-18 04:47发布

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.

The Application icon is set in the project file: <ApplicationIcon>MyIcon.ico</ApplicationIcon>

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.

2条回答
狗以群分
2楼-- · 2019-07-18 05:06

I tried right-clicking a project, choosing Properties, and clicking the Application tab. This is where you can change the icon file. However, the Configuration and Platform dropdowns are disabled. This confirms that if you can have different icon files for different builds, it's not going to be the easy way.

If you do any scripting to customize your build, you could 'preprocess' your *.csproj file, setting ApplicationIcon based on the desired build, then build the project.

查看更多
我命由我不由天
3楼-- · 2019-07-18 05:09

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>

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>

EDIT: Pretend the above uses and properly evaluates $(Configuration) property values rather than $(Platform)

查看更多
登录 后发表回答