2017-08-02 162 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