How to run VCUpgrade before Appveyor build?
Asked Answered
N

2

10

We distribute a set of Visual Studio 2010 project files. Users are expected to upgrade to suit their taste. Our .appveyor.yml file includes the following images (in addition to configurations and platforms):

  • Visual Studio 2017
  • Visual Studio 2015
  • Visual Studio 2013
  • Visual Studio 2012
  • Visual Studio 2010

The Visual Studio 2017 build failed with:

Build started
git clone -q --depth=3 --branch=master https://github.com/noloader/cryptopp.git C:\projects\cryptopp
git checkout -qf 3504f1da2591d8b84e356527ed41dc6209eafa06
msbuild "C:\projects\cryptopp\cryptest.sln" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(55,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 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]
Command exited with code 1

The text of interest is:

error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 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".

When I am working from developer command prompts, I run VCUpgrade or I use GitBash and sed -i s'|Tools>v100|Tools>v120' *vcxproj* to change the platform toolset.

When I try to run it through the AppVeyor test_script:, it results in another failure. For example, from the 1.0.131 build log:

...
vcupgrade.exe -nologo -overwrite cryptlib.vcxproj
'vcupgrade.exe' is not recognized as an internal or external command,
operable program or batch file.
Command exited with code 1

My question is, how do we tell Appveyor to change the platform toolset? Is there a step or configuration option to run VCUpgrade? Or do we do something else?


This is the help provided when running VCUpgrade locally:

> vcupgrade
Microsoft (R) Visual C++ Project Convert Utility - Version 11.00.61030
Copyright (C) Microsoft Corporation. All rights reserved.

  Usage: VCUpgrade [options] <project file>

  Options:
     -nologo            Suppresses the copyright message
     -nocolor           Do not output error and warning messages in color
     -overwrite         Overwrite existing files
     -PersistFramework  Keep the Target Framework Version while upgrading. (-p)
Northwestward answered 16/4, 2017 at 19:34 Comment(1)
Can't you run vcupgrade or devenv /upgrade or so as a pre-build step in Appveyor? Or, instead of setting PlatformToolset to a fixed number and constantly fiddling with it, set it to $(DefaultPlatformToolset) and the toolset will be correct automatically and according to the version of VS/environment which opens the project.Headword
J
5

AppVeyor currently provides build worker images with VS 2013, 2015 and 2017. There are no plans to add VS 2010 and 2012 at the moment, sorry.

Interesting option for you could be custom build environment. It is "hybrid" solution where you own infrastructure and images, and AppVeyor provides UI and orchestration. Documentation for Azure and Hyper-V is available now, documentation for other providers is on it's way.

Note that custom build environments are available for Premium plan customers now. If you want to try, please mail to team at appveyor.com.

Jayejaylene answered 19/4, 2017 at 0:2 Comment(1)
Thanks @ilyaf. We can remove VS2010 and VS2012. How do we run VCUpgrade or sed?Northwestward
H
5

VCUpgrade might not exist depending on the toolset used. For example I have it for VS2013, VS2015 but not for VS2017. The corresponding functionality is devenv /upgrade my.vcxproj though which is available at least from VS2013, possibly earlier. And you can run it as an extra build step in Appveyor, were it not that you use a custom project file layout which devenv doesn't want to touch.

Either make your project file compatible with multiple VS versions by replacing V100 in your project file $(DefaultPlatformToolset), as layed out in the other question on this subject, or replace V100 manually. I don't know if appveyor has sed in the path by default but you can do Powershell builds instead and PS has sed-like capabilities. You do need to derive the toolset manually depending on the build worker image used though. Something like this does the trick:

configuration:

- Debug
- Release

platform:

- x86
- x64

image:

- Visual Studio 2017
- Visual Studio 2015
- Visual Studio 2013

build_script:

- ps: >-

    if ($env:APPVEYOR_BUILD_WORKER_IMAGE -eq "Visual Studio 2013") {
      $PlatformToolset = "v120"
    } elseif ($env:APPVEYOR_BUILD_WORKER_IMAGE -eq "Visual Studio 2015") {
      $PlatformToolset = "v140"
    } else {
      $PlatformToolset = "v141"
    }

    (Get-Content cryptlib.vcxproj) | %{$_ -replace "v100", $PlatformToolset} | Set-Content cryptlib.vcxproj

    (Get-Content cryptest.vcxproj) | %{$_ -replace "v100", $PlatformToolset} | Set-Content cryptest.vcxproj

    & msbuild cryptlib.vcxproj "/p:platform=$env:platform;configuration=$env:configuration"

    & msbuild cryptest.vcxproj "/p:platform=$env:platform;configuration=$env:configuration"
Headword answered 2/8, 2017 at 10:41 Comment(6)
Thanks @stinj. "[VCUpgrade] does not exist in more recent versions..." - It seems like Microsoft feels VCUpgrade is the tool of the future: To the command line enthusiasts: Some quick know-hows for Upgrading to VS 2010. Its also available in my developer prompts from VS2010 - VS2013. I wish Microsoft would publish some decent documentation instead of forcing people to read those blogs. I despise them, and there's no telling when they become obsolete (q.v.).Northwestward
Either make your project file compatible with multiple VS versions by replacing V100 in your project file $(DefaultPlatformToolset)..." - Yeah, the problem is, DefaultPlatformToolset is undocumented. You can't find anything about DefaultPlatformToolset on MSDN or in a blog, either. Man, I wish Microsoft would publish some decent documentation.Northwestward
Indeed vcupgrade is still in VS2013 and even VS2015 it seems, I'll edit that out.Headword
And yes copy is easier, but you just duplicated hundreds of lines. Even if automated, they're still checked in. And it doesn't really shine for local builds.Headword
Actually what you did is incorrect, read my answer https://mcmap.net/q/1165795/-how-to-set-platformtoolset-property-from-msbuild carefully: $(DefaultPlatformToolset) must come after Microsoft.Cpp.Default.props else it is not defined.Headword
Thanks @stijn. "Actually what you did is incorrect..." - I actually tried that at Commit ac513c06f8c80. Things broke even worse - both Win32 and x64 failed. By the way, VCUpgrade put them in the wrong order. "Them" are the global property group with the UUID and PlatformToolset and the import statements. Let me go back and revert the revert.Northwestward

© 2022 - 2024 — McMap. All rights reserved.