根据定义C#更改exe图标 [英] Change exe icon based on define C#

查看:455
本文介绍了根据定义C#更改exe图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为两个不同的人创建一个项目,我想通过define更改图标。例如:

  #if customer1 
//添加代码以选择c:\ path to resources \ myimage1 .ico for exe icon
#else
//添加代码以选择c:\ path to resources \ myimage2.ico for exe icon
#endif

我知道你可以在这里手动选择你想要的图标:




  • 重复这些步骤,为每个客户添加特定于发行版的配置。


  • I am creating a project for two different people and I would like to change the icon via define. For example:

    #if customer1
    //add code to select c:\path to resources\myimage1.ico for exe icon
    #else
    //add code to select c:\path to resources\myimage2.ico for exe icon
    #endif
    

    I know you can manually select which icon you want here:

    https://msdn.microsoft.com/en-us/library/339stzf7.aspx

    But the define way make sense for us using git so we don't have to keep reuploading someone else's image. We can simply just put the define and have it use that image. Thanks.

    解决方案

    You can modify the csproj file so that you create different build configurations for the two customers. For example, you can do the following:

    1. Unload the project by right-clicking on the project in the Solution Explorer within Visual Studio and clicking "Unload Project".

    2. Right-click on your unloaded project and click "Edit "

    3. Find the "ApplicationIcon" tag and replace it with two conditional PropertyGroups, like this:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
      <ApplicationIcon>icon.ico</ApplicationIcon>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
      <ApplicationIcon>netfol.ico</ApplicationIcon>
    </PropertyGroup>

    This will create a debug build configuration for Customer1 and Customer2.

    1. Do the same on your icon ItemGroup, also in the project file, like this:

    <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
      <Content Include="icon.ico" />
    </ItemGroup>
    <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
      <Content Include="netfol.ico" />
    </ItemGroup>

    1. Find the PropertyGroup for the configuration, itself. It will have this line:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

    1. Below this group, add groups for the debug configuration for your two new debug customer configurations, like this:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
      <PlatformTarget>AnyCPU</PlatformTarget>
      <DebugSymbols>true</DebugSymbols>
      <DebugType>full</DebugType>
      <Optimize>false</Optimize>
      <OutputPath>bin\Debug_Customer1\</OutputPath>
      <DefineConstants>DEBUG;TRACE</DefineConstants>
      <ErrorReport>prompt</ErrorReport>
      <WarningLevel>4</WarningLevel>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
      <PlatformTarget>AnyCPU</PlatformTarget>
      <DebugSymbols>true</DebugSymbols>
      <DebugType>full</DebugType>
      <Optimize>false</Optimize>
      <OutputPath>bin\Debug_Customer2\</OutputPath>
      <DefineConstants>DEBUG;TRACE</DefineConstants>
      <ErrorReport>prompt</ErrorReport>
      <WarningLevel>4</WarningLevel>
    </PropertyGroup>

    1. Click Save.

    2. Right-click on the project file in the Solution Explorer and click "Reload Project". Say yes if Visual Studio asks if you want to close the project file.

    3. Now when you want to build for different customers, go to Build\Configuration Manager and select the customer-specific configuration.

    4. Repeat these steps to add release-specific configurations for each customer.

    这篇关于根据定义C#更改exe图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆