2017-08-02 130 views
0

我们是experiencing AppVeyor x64 build failures,并试图建议set PlatformToolset to DefaultPlatformToolset。该属性值没有记录,所以我们想彻底测试它。如何从MSbuild中设置PlatformToolset属性?

我们有线DefaultPlatformToolset到我们AppVeyor configuration file

test_script: 

- cmd: >- 
    msbuild /t:Build /p:PlatformToolset=DefaultPlatformToolset cryptlib.vcxproj 
    msbuild /t:Build /p:PlatformToolset=DefaultPlatformToolset cryptest.vcxproj 
    msbuild /t:CopyCryptestToRoot /p:PlatformToolset=DefaultPlatformToolset cryptest.vcxproj 
    cryptest.exe v 
    cryptest.exe tv all 

DefaultPlatformToolset导致AppVeyor故障。从日志这里我们相信一切是正确的:Build 1.0.129

msbuild /t:Build /p:PlatformToolset=DefaultPlatformToolset cryptlib.vcxproj 
Microsoft (R) Build Engine version 14.0.25420.1 
Copyright (C) Microsoft Corporation. All rights reserved. 
Build started 8/2/2017 5:14:24 AM. 
The target "_ConvertPdbFiles" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (45,37)" does not exist in the project, and will be ignored. 
The target "_CollectPdbFiles" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (45,70)" does not exist in the project, and will be ignored. 
The target "_CollectMdbFiles" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (52,38)" does not exist in the project, and will be ignored. 
The target "_CopyMdbFiles" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (52,71)" does not exist in the project, and will be ignored. 
Project "C:\projects\cryptopp\cryptlib.vcxproj" on node 1 (Build target(s)). 
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for DefaultPlatformToolset (Platform Toolset = 'DefaultPlatformToolset') cannot be found. To build using the DefaultPlatformToolset build tools, please install DefaultPlatformToolset build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\projects\cryptopp\cryptlib.vcxproj] 
Done Building Project "C:\projects\cryptopp\cryptlib.vcxproj" (Build target(s)) -- FAILED. 
Build FAILED. 

我们如何使用的MSBuild建设项目时,设置在命令行上PlatformToolset


这些都不起作用。他们产生与上述类似的错误。

> msbuild /t:Build /p:PlatformToolset=DefaultPlatformToolset cryptlib.vcxproj 

> msbuild /t:Build /p:PlatformToolset=$(DefaultPlatformToolset) cryptlib.vcxproj 

> msbuild /t:Build /p:PlatformToolset="$(DefaultPlatformToolset)" cryptlib.vcxproj 

> msbuild /t:Build /p:PlatformToolset='$(DefaultPlatformToolset)' cryptlib.vcxproj 

这里尝试这样做,愚蠢的MS XML引用时,另一个错误:

>msbuild /t:Build /p:PlatformToolset="$(DefaultPlatformToolset)" cryptlib.vcxproj 
Microsoft (R) Build Engine version 4.6.1087.0 
[Microsoft .NET Framework, version 4.0.30319.42000] 
Copyright (C) Microsoft Corporation. All rights reserved. 

MSBUILD : error MSB1011: Specify which project or solution file to use because t 
his folder contains more than one project or solution file. 
'#34' is not recognized as an internal or external command, 
operable program or batch file. 
'#34' is not recognized as an internal or external command, 
operable program or batch file. 

然后还有这样一条:

> msbuild /t:Build /p:PlatformToolset=""$(DefaultPlatformToolset)"" cryptlib.vcxproj 
Microsoft (R) Build Engine version 4.6.1087.0 
[Microsoft .NET Framework, version 4.0.30319.42000] 
Copyright (C) Microsoft Corporation. All rights reserved. 

Build started 8/2/2017 2:19:15 AM. 
Project "c:\Users\Test\cryptlib.vcxproj" on node 1 (Build target(s)). 
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.p 
rops(15,24): error MSB4115: The "exists" function only accepts a scalar value, 
but its argument "$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\$(Pla 
tformToolset)\Microsoft.Cpp.$(Platform).$(PlatformToolset).props" evaluates to 
"C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\\Platforms\x64\Platform 
Toolsets\"$(DefaultPlatformToolset)"\Microsoft.Cpp.x64."$(DefaultPl 
atformToolset)".props" which is not a scalar value. 

关于错误消息的建议。 ..或右键单击解决方案,然后选择“重定向解决方案”,我们不能。这是远程命令行。我们试图弄清楚如何从命令行运行VCUpgrade,在How to run VCUpgrade before Appveyor build?

回答

2

DefaultPlatformToolset是一个MSBuild属性,它被设置在主项目导入的平台.props文件之一中。在一个C++项目文件中的一个点,应该有一个线

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 

它例如用于VS2017最终反过来进口<msbuild installation>\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.props,这台使用

<DefaultPlatformToolset>v140</DefaultPlatformToolset> 

的性质,因为这是一个MSBuild属性它不被Appveyor或cmd所知,因此你不能直接从appveyor.yml中引用它。即使它是已知的,也不能使用$(DefaultPlatformToolset)这是msbuild属性扩展语法来引用它,而cmd的形式是%ABC%。所有的错误都是因为PlatformToolset属性被设置为例如字符串'DefaultPlatformToolset',而它需要设置为实际可用平台的名称,如v110或v140或v120_xp或...

如果要使用DefaultPlatformToolset,最简单的方法是将其输入到项目文件中。如果需要,它仍然可以从命令行重写。另一种方法是运行msbuild并打印它的值,然后使用/ p:PlatformToolset =来传递它。但是这对Visual Studio中的本地开发构建来说不是那么好。

对于改变项目文件,发现其中PlatformToolset定义的部分(S)和其更改为$(DefaultPlatformToolset) -在这之后应该来的Microsoft.Cpp.Default.props导入其他财产可能不尚未定义。为防止出于某种原因没有定义DefaultPlatformToolset(某些自定义或可能是旧的VS版本)的平台构建的情况,请将其设置为明智的默认首先,,然后,Microsoft.Cpp.Default.props。例如:

<PropertyGroup Label="Globals"> 
    <PlatformToolset>v100</PlatformToolset> 
</PropertyGroup> 
.... 
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
.... 
<PropertyGroup> 
    <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> 
</PropertyGroup> 

这里是另一种方式来做到这一点:

<!-- Use DefaultPlatformToolset after Microsoft.Cpp.Default.props --> 
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
<!-- Set DefaultPlatformToolset to v100 (VS2010) if not defined --> 
<PropertyGroup Label="EmptyDefaultPlatformToolset"> 
    <DefaultPlatformToolset Condition=" '$(DefaultPlatformToolset)' == '' ">v100</DefaultPlatformToolset> 
    </PropertyGroup> 
<PropertyGroup Label="PlatformToolset"> 
    <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> 
</PropertyGroup> 

还有一点也很重要,以确保Microsoft.Cpp.Default.props导入前的全球属性组元素设置。如果未设置它们,然后MSBuild的假设一个Application正在建设,而忽略后来来了ConfigurationType

<PropertyGroup Label="Globals"> 
    <ProjectGuid>{016d3861-ccd6-4a50-83b4-fe4e93bea333}</ProjectGuid> 
    <RootNamespace>mylib</RootNamespace> 
    <ConfigurationType>StaticLibrary</ConfigurationType> 
</PropertyGroup> 
... 
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
... 
<PropertyGroup> 
    <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> 
</PropertyGroup> 
+0

不知道,我不知道它有什么关系积极拒绝它,也许只是没有时间/兴趣去记录内部 – stijn