在项目中指定Windows SDK,props,directory.build.target,命令行...优先顺序是什么?
Specifying Windows SDK in project, props, directory.build.target, command-line... what is the order of precedence?
- 我们的许多 C++ vcxproj 文件都指定了一个确切的 Windows SDK 版本,而多年来人们已经设置了它……很乱。
- 为了解决这个问题,我们创建了
Company.props
文件来指定首选版本,理论上每个项目都会添加该版本...除非不是。
- 我发现您可以在 directory.build.props/.target 中进行设置。所以我们添加了一个复制 Company.props 用于在我们的构建机器上错过上述的所有项目(我不认为这是在 VS 中构建时使用的)。
- 您还可以将参数传递给 msbuild.exe
/p:WindowsTargetPlatformVersion=10.0.18362.0
,以便在我们的 Azure DevOps 构建步骤中进行设置。
我认为这是优先顺序,例如2 覆盖 1,4 覆盖 1,2 & 3 - 这是正确的吗?
我不想在比需要更多的地方指定它,因为它们有更多机会不同步!
I think this is the order of precedence e.g. 2 overrides 1, 4 overrides 1,2 &3 – is this correct?
是,正确。
实际上,3 -> Directory.Build.props
文件是普通 .props
文件的更新。 Directory.Build.props
避免手动添加自定义 .props
文件到解决方案中的每个项目文件。 Here 它解释了。
所以 2 和 3 应该是非常相似的东西。 3 比 2 好。
对于4,就像你说的那样,4覆盖了1,2&3。由于它使用了“命令”,因此该命令将需要重新分配的已使用属性更直接地分配给运行.
在我这边做了一个小测试。(没有使用DevOps,在本地测试但应该是一样的)
我创建了一个简单的普通 C++ 控制台项目只是为了测试,并在项目的 属性 页面中设置 WindowsTargetPlatformVersion = 10.0.19041.0。
创建了两个文件,一个名为Directory.Build.props
,另一个名为MyProps.props
。(关于创建MyProps.props
文件的原因,参考这个doc)
在Directory.Build.props
文件中,添加了以下代码:
<Project>
<PropertyGroup>
<ForceImportAfterCppProps>$(MsbuildThisFileDirectory)\MyProps.props
</ForceImportAfterCppProps>
</PropertyGroup>
</Project>
在MyProps.props
文件中,添加了以下代码:
<Project>
<PropertyGroup>
<WindowsTargetPlatformVersion>10.0.17763.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
</Project>
已将它们保存到项目文件夹中。
测试 1
直接在 VS 中构建此项目,构建 results/detailed 输出显示 WindowsTargetPlatformVersion
重新分配为“10.0.17763.0”,并且还显示之前的值 =“10.0.19041.0”。
测试 2
启动了 Developer Command Prompt for VS 2019
和 运行 这个 MSBuild 命令:
msbuild myproject.sln /p:WindowsTargetPlatformVersion=10.0.18362.0 -detailedSummary -fileLogger
构建成功并生成了一个记录构建输出的日志文件(msbuild.log)。在此日志文件中,您可以看到记录了 10.0.18362.0
并且与 Property reassignment
.
相关
当然,我也看到了这条消息The "WindowsTargetPlatformVersion" property is a global property, and cannot be modified.
,所以我不确定,但也许通过在 MSBuild 命令行中设置和使用它来更改 WindowsTargetPlatformVersion
属性可能有问题, 它应该是另一个 issue/question.
总结
如果“WindowsTargetPlatformVersion”属性 可以在 MSBuild 命令行中 changed/set(我没有测试更多条件或测试其他属性),则 4 会覆盖 1,2 和 3。
- 我们的许多 C++ vcxproj 文件都指定了一个确切的 Windows SDK 版本,而多年来人们已经设置了它……很乱。
- 为了解决这个问题,我们创建了
Company.props
文件来指定首选版本,理论上每个项目都会添加该版本...除非不是。 - 我发现您可以在 directory.build.props/.target 中进行设置。所以我们添加了一个复制 Company.props 用于在我们的构建机器上错过上述的所有项目(我不认为这是在 VS 中构建时使用的)。
- 您还可以将参数传递给 msbuild.exe
/p:WindowsTargetPlatformVersion=10.0.18362.0
,以便在我们的 Azure DevOps 构建步骤中进行设置。
我认为这是优先顺序,例如2 覆盖 1,4 覆盖 1,2 & 3 - 这是正确的吗? 我不想在比需要更多的地方指定它,因为它们有更多机会不同步!
I think this is the order of precedence e.g. 2 overrides 1, 4 overrides 1,2 &3 – is this correct?
是,正确。
实际上,3 -> Directory.Build.props
文件是普通 .props
文件的更新。 Directory.Build.props
避免手动添加自定义 .props
文件到解决方案中的每个项目文件。 Here 它解释了。
所以 2 和 3 应该是非常相似的东西。 3 比 2 好。
对于4,就像你说的那样,4覆盖了1,2&3。由于它使用了“命令”,因此该命令将需要重新分配的已使用属性更直接地分配给运行.
在我这边做了一个小测试。(没有使用DevOps,在本地测试但应该是一样的)
我创建了一个简单的普通 C++ 控制台项目只是为了测试,并在项目的 属性 页面中设置 WindowsTargetPlatformVersion = 10.0.19041.0。
创建了两个文件,一个名为Directory.Build.props
,另一个名为MyProps.props
。(关于创建MyProps.props
文件的原因,参考这个doc)
在Directory.Build.props
文件中,添加了以下代码:
<Project>
<PropertyGroup>
<ForceImportAfterCppProps>$(MsbuildThisFileDirectory)\MyProps.props
</ForceImportAfterCppProps>
</PropertyGroup>
</Project>
在MyProps.props
文件中,添加了以下代码:
<Project>
<PropertyGroup>
<WindowsTargetPlatformVersion>10.0.17763.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
</Project>
已将它们保存到项目文件夹中。
测试 1
直接在 VS 中构建此项目,构建 results/detailed 输出显示 WindowsTargetPlatformVersion
重新分配为“10.0.17763.0”,并且还显示之前的值 =“10.0.19041.0”。
测试 2
启动了 Developer Command Prompt for VS 2019
和 运行 这个 MSBuild 命令:
msbuild myproject.sln /p:WindowsTargetPlatformVersion=10.0.18362.0 -detailedSummary -fileLogger
构建成功并生成了一个记录构建输出的日志文件(msbuild.log)。在此日志文件中,您可以看到记录了 10.0.18362.0
并且与 Property reassignment
.
当然,我也看到了这条消息The "WindowsTargetPlatformVersion" property is a global property, and cannot be modified.
,所以我不确定,但也许通过在 MSBuild 命令行中设置和使用它来更改 WindowsTargetPlatformVersion
属性可能有问题, 它应该是另一个 issue/question.
总结
如果“WindowsTargetPlatformVersion”属性 可以在 MSBuild 命令行中 changed/set(我没有测试更多条件或测试其他属性),则 4 会覆盖 1,2 和 3。