You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio中从同一项目同时构建两个不同图标版本的EXE

How to Build Multiple Versions with Different Icons in One Go in Visual Studio

Absolutely feasible! You don't have to manually switch build constants and run builds twice—here are two straightforward approaches to set up automatic simultaneous builds for both your standard and custom icon versions:

Approach 1: Use Multiple Build Configurations (Visual Studio UI-Friendly)

This is the most intuitive method if you prefer working within Visual Studio's graphical interface:

  • Open your project's Properties (right-click the project > Properties).
  • Go to the Configuration Manager (found in the dropdown at the top of the properties window, next to "Platform").
  • Create a new solution configuration:
    1. Click the dropdown under "Active solution configuration" and select <New...>.
    2. Name it something like Release_Other, base it on your existing Release configuration, and check the box to "Create new project configurations".
  • For the new Release_Other configuration:
    1. Switch to the Build tab in project properties.
    2. Add OTHER_VERSION to the Conditional compilation symbols field (separate from existing symbols with a semicolon if needed).
  • Configure output paths to avoid overwrites:
    In each configuration's Build > Output settings, set a unique output directory (e.g., bin\Release\Standard for the default config, bin\Release\Other for the new one).
  • Trigger the simultaneous build:
    Back in Configuration Manager, check the "Build" box for both your original configuration (e.g., Release) and the new Release_Other configuration. Click Close, then run a solution build—Visual Studio will build both versions in one shot, each using its assigned icon.

Approach 2: Custom MSBuild Targets (Advanced, Flexible)

If you prefer scripting the build process directly in the project file, you can add custom MSBuild targets to trigger both builds with a single command:

  1. Unload your project in Visual Studio (right-click the project > Unload Project), then edit the .csproj/.vbproj file.
  2. Add the following XML at the end of the file (before the closing </Project> tag):
<Target Name="BuildBothVersions" DependsOnTargets="BuildStandard;BuildOther">
</Target>

<Target Name="BuildStandard">
  <MSBuild 
    Projects="$(MSBuildProjectFile)" 
    Properties="DefineConstants=;OutputPath=bin\Standard\$(Configuration)" 
    Targets="Build"
  />
</Target>

<Target Name="BuildOther">
  <MSBuild 
    Projects="$(MSBuildProjectFile)" 
    Properties="DefineConstants=OTHER_VERSION;OutputPath=bin\Other\$(Configuration)" 
    Targets="Build"
  />
</Target>
  1. Reload the project. Now you can:
    • Run the custom target from Visual Studio's Command Window with Build.BuildBothVersions.
    • Or execute it via command line with msbuild YourProject.csproj /t:BuildBothVersions.

Your existing ApplicationIcon property group will work perfectly with either approach—MSBuild will pick the correct icon based on whether OTHER_VERSION is defined in each build context.

内容的提问来源于stack exchange,提问作者Andreas Zita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:23:35