How to set PlatformToolset property from MSbuild?

前端 未结 1 454
感情败类
感情败类 2021-01-26 11:49

We are experiencing AppVeyor x64 build failures, and trying a suggestion to set PlatformToolset to DefaultPlatformToolset. The property value is undocumented, so we want to thor

1条回答
  •  梦毁少年i
    2021-01-26 12:56

    DefaultPlatformToolset is an MSBuild property which gets set in one of the platform .props files imported by the main project. At one point in a C++ project file there should be the line

    
    

    which for instance for VS2017 ends up importing \Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.props in turn, which sets the property using

    v140
    

    Since this is an msbuild property it is not known by Appveyor nor by cmd and as such you cannot reference it directly from within appveyor.yml. And even if it were known, you cannot refer to it using $(DefaultPlatformToolset) which is msbuild property expansion syntax whereas cmd's is of the form %ABC%. The errors you get are all because the PlatformToolset property gets set to e.g. the string 'DefaultPlatformToolset' whereas it needs to be set to the name of an actual available platform like v110 or v140 or v120_xp or ...

    If you want to use DefaultPlatformToolset the easiest way is entering it in the project file. It can still be overriden from the commandline if needed. The alternative would be running msbuild and have it print it's value, then pass that using /p:PlatformToolset=. But that's not so nice for local development builds in Visual Studio.

    For changing the project file, find the section(s) where the PlatformToolset is defined and change it to $(DefaultPlatformToolset) - this should come after the Microsoft.Cpp.Default.props import else the property might not yet be defined. To guard against the case where you're building for a platform which for some reason does not define DefaultPlatformToolset (something custom, or possibly old VS versions) set it to a sensible default first, before the Microsoft.Cpp.Default.props. Example:

    
      v100
    
    ....
    
    ....
    
      $(DefaultPlatformToolset)
    
    

    Here's another way to do it:

    
    
    
    
        v100
      
    
        $(DefaultPlatformToolset)
    
    

    It is also very important to ensure the Global property group elements are set before Microsoft.Cpp.Default.props is imported. If they are not set, then MSbuild assumes an Application is being built, and it ignores the ConfigurationType that comes later:

    
        {016d3861-ccd6-4a50-83b4-fe4e93bea333}
        mylib
        StaticLibrary
    
    ...
    
    ...
    
        $(DefaultPlatformToolset)
    
    

    0 讨论(0)
提交回复
热议问题