我正在为两个不同的人创建一个项目,我想通过定义更改图标。例如:
#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
我知道您可以在这里手动选择您想要的图标:
https://msdn.microsoft.com/en-us/library/339stzf7.aspx
但定义方式对于我们使用 git 来说是有意义的,因此我们不必不断重新上传别人的图像。我们可以简单地放置定义并让它使用该图像。谢谢。
您可以修改 csproj 文件,以便为两个客户创建不同的构建配置。例如,您可以执行以下操作:
通过右键单击 Visual Studio 中解决方案资源管理器中的项目并单击“卸载项目”来卸载项目。
右键单击已卸载的项目,然后单击“编辑”
找到“ApplicationIcon”标签并将其替换为两个条件 PropertyGroup,如下所示:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<ApplicationIcon>netfol.ico</ApplicationIcon>
</PropertyGroup>
这将为 Customer1 和 Customer2 创建调试构建配置。
- 在项目文件中的图标 ItemGroup 上执行相同的操作,如下所示:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer1|AnyCPU' ">
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Customer2|AnyCPU' ">
<Content Include="netfol.ico" />
</ItemGroup>
- 找到配置本身的 PropertyGroup。它将有这一行:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- 在此组下方,为两个新的调试客户配置添加调试配置组,如下所示:
<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>
单击“保存”。
在解决方案资源管理器中右键单击项目文件,然后单击“重新加载项目”。如果 Visual Studio 询问您是否要关闭项目文件,请选择“是”。
Now when you want to build for different customers, go to Build\Configuration Manager and select the customer-specific configuration.
- 重复这些步骤为每个客户添加特定于版本的配置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)