【问题标题】:With different configurations in a solution, how can you specify different build types (DLL or Static Lib) for a project in the solution?对于解决方案中的不同配置,如何为解决方案中的项目指定不同的构建类型(DLL 或静态库)?
【发布时间】:2020-01-21 19:08:08
【问题描述】:

我有一个包含多个项目和配置的 VisualStudio 解决方案。

对于其中一个项目,我想为不同的配置使用不同的配置类型(DLL 或静态库)。

例如,对于配置“Debug|Win32”,我想为该项目构建一个 DLL,对于配置“Static Release|x64”,我想构建一个静态库。

当我尝试为这些配置之一设置配置类型时,这是为所有配置设置的类型,因此所有配置似乎总是“DLL”或所有配置的“静态库”。

我有一个示例,其中可能会有所不同,但我无法弄清楚这是如何实现的。还是您必须“破解” vcxproj 文件?

【问题讨论】:

  • 您需要单独的项目。

标签: dll configuration visual-studio-2017 static-libraries


【解决方案1】:

其实事实证明这是可以的,但是需要编辑项目文件。

项目文件是 xml 格式,你应该找到这样的条目

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">...</PropertyGroup>

在带有条件的PropertyGroup 中,添加您需要的ConfigurationType,例如

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <PlatformToolset>v141</PlatformToolset>
</PropertyGroup>

变成

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  <PlatformToolset>v141</PlatformToolset>
  <ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <PlatformToolset>v141</PlatformToolset>
  <ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>

我发现这是可行的,但像往常一样手动编辑 xml 时要小心,确保有备份,以防弄乱语法或 xml 嵌套。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多