Visual studio 如何在visual studio 2017和visual studio 2019之间为每个项目引用一份vcxproj.filters和vcxproj.user 我在VisualStudio 2017社区版中创建了一个C++项目,我已经打开并用VisualStudio 2019社区版“转换”了它。 项目文件夹包含: Main.sln Main/Main.vcxproj Main/Main.vcxproj.filters Main/Main.vcxproj.user

Visual studio 如何在visual studio 2017和visual studio 2019之间为每个项目引用一份vcxproj.filters和vcxproj.user 我在VisualStudio 2017社区版中创建了一个C++项目,我已经打开并用VisualStudio 2019社区版“转换”了它。 项目文件夹包含: Main.sln Main/Main.vcxproj Main/Main.vcxproj.filters Main/Main.vcxproj.user,visual-studio,visual-c++,visual-studio-2017,visual-studio-2019,Visual Studio,Visual C++,Visual Studio 2017,Visual Studio 2019,根据Winmerge,转换仅影响Main/Main.vcxproj中的两个值: <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> ... <PlatformToolset>v141</PlatformToolset> 10.0.17134.0 ... v141 改为 <WindowsTargetPlatformVersion>10.0&

根据Winmerge,转换仅影响Main/Main.vcxproj中的两个值:

<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
...
<PlatformToolset>v141</PlatformToolset>
10.0.17134.0
...
v141
改为

<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
...
<PlatformToolset>v142</PlatformToolset>
10.0
...
v142
对于VS2017和VS2019,有哪些选项可用于维护大部分或所有项目文件的一个副本? 此外,我想知道:

  • 在.vcxproj或.sln中是否支持条件语句
  • 是否有一种方法可以显式指向一个文件夹路径中的.vcxproj并 *.vcxproj.filters和*.vcxproj.user在另一个中


谢谢

希望这会对以后的人有所帮助

可以设置可用宏的关键帧。我还发现,可以通过在文件中进一步设置来替换值

讨论检查和设置VisualStudioVersion宏

我找到的解决方案使用DefaultPlatformToolset宏,VS2017为v141,VS2019为v142

Main.vcxproj可以通过两种方式在条件中使用此选项:

1) 在包含必要值的PropertyGroup周围使用Choose、When和Others标记:

<Choose>
  <When Condition="'$(DefaultPlatformToolset)'=='v141'">
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>v141</PlatformToolset>
    </PropertyGroup>
  </When>
  <When Condition="'$(DefaultPlatformToolset)'=='v142'">
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>v142</PlatformToolset>
    </PropertyGroup>
  </When>
  <Otherwise>
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
    </PropertyGroup>
  </Otherwise>
</Choose>

10.0.17134.0
v141
10
v142
$(DefaultWindowsSDKVersion)
$(DefaultPlatformToolset)
2) 设置PropertyGroup的条件属性:

<PropertyGroup Label="Globals">
  <WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v141'" Label="Globals">
  <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v142'" Label="Globals">
  <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>

$(DefaultWindowsSDKVersion)
10.0.17134.0
10
另一种方法可能是根据Visual Studio版本使用.sln文件,并在$(SolutionFileName)宏上使用基本条件


...
...

希望这会对以后的人有所帮助

可以设置可用宏的关键帧。我还发现,可以通过在文件中进一步设置来替换值

讨论检查和设置VisualStudioVersion宏

我找到的解决方案使用DefaultPlatformToolset宏,VS2017为v141,VS2019为v142

Main.vcxproj可以通过两种方式在条件中使用此选项:

1) 在包含必要值的PropertyGroup周围使用Choose、When和Others标记:

<Choose>
  <When Condition="'$(DefaultPlatformToolset)'=='v141'">
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>v141</PlatformToolset>
    </PropertyGroup>
  </When>
  <When Condition="'$(DefaultPlatformToolset)'=='v142'">
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>v142</PlatformToolset>
    </PropertyGroup>
  </When>
  <Otherwise>
    <PropertyGroup Label="Globals">
      <WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
    </PropertyGroup>
    <PropertyGroup Label="Configuration">
      <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
    </PropertyGroup>
  </Otherwise>
</Choose>

10.0.17134.0
v141
10
v142
$(DefaultWindowsSDKVersion)
$(DefaultPlatformToolset)
2) 设置PropertyGroup的条件属性:

<PropertyGroup Label="Globals">
  <WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v141'" Label="Globals">
  <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(DefaultPlatformToolset)'=='v142'" Label="Globals">
  <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>

$(DefaultWindowsSDKVersion)
10.0.17134.0
10
另一种方法可能是根据Visual Studio版本使用.sln文件,并在$(SolutionFileName)宏上使用基本条件


...
...

我使用了华中科技大学的解决方案,将其转换为2015年和2019年

<!--
    Switch the PlatformToolset based on the Visual Studio Version
-->
<PropertyGroup>
    <!-- Assume Visual Studio 2015 / 14.0 as the default -->
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
</PropertyGroup>
<!-- Visual Studio 2019 (16.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '16.0'">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseOfMfc>false</UseOfMfc>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<!-- Visual Studio 2015 (14.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseOfMfc>false</UseOfMfc>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<!--
    End of: Switch the PlatformToolset based on the Visual Studio Version
-->

14
动态图书馆
假的
多字节
v142
动态图书馆
假的
多字节
v140

工作起来很有魅力…

我使用了华中科技大学的解决方案,将其转换到2015年和2019年

<!--
    Switch the PlatformToolset based on the Visual Studio Version
-->
<PropertyGroup>
    <!-- Assume Visual Studio 2015 / 14.0 as the default -->
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
</PropertyGroup>
<!-- Visual Studio 2019 (16.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '16.0'">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseOfMfc>false</UseOfMfc>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<!-- Visual Studio 2015 (14.0) -->
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseOfMfc>false</UseOfMfc>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<!--
    End of: Switch the PlatformToolset based on the Visual Studio Version
-->

14
动态图书馆
假的
多字节
v142
动态图书馆
假的
多字节
v140

工作起来很有魅力…

我只能说,我看到它是通过命名约定完成的,以区分次要目标的解决方案/项目文件。长时间维护这两者都会很痛苦。哦,所以它可能类似于Main17.sln/.vcxproj和Main19.sln/.vcxproj,但是普通的.vcxproj.filter和.vcxproj.user?不,我不是有意暗示。我假设有两套完整的解决方案/项目文件。我只能说,我已经看到使用命名约定来区分次要目标的解决方案/项目文件。长时间维护这两者都会很痛苦。哦,所以它可能类似于Main17.sln/.vcxproj和Main19.sln/.vcxproj,但是普通的.vcxproj.filter和.vcxproj.user?不,我不是有意暗示。我假设有两套完整的解决方案/项目文件。