0

A Visual Studio project can be upgraded from the command line using the devenv.exe command as follows:

  devenv.exe SOLUTION_PATH /Upgrade

Where SOLUTION_PATH is a path to a Visual Studio solution (or project) file.

What is the most direct way to perform this step as part of a GitHub action?

What I Have Tried

So far I have failed to find a way to get devenv.exe into the path of the GitHub Action. There does not appear to be a prebuilt action step for this (setup-msbuild step does not make devenv available). Even hardcoding a path such as

 MSDEVENV_PATH: ${{'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com'}}

... then later ...

run: ${{env.MSDEVENV_PATH}} ${{env.SOLUTION_FILE_PATH}} /Upgrade

fails because the path contains spaces, and I can find no way to add quotation marks.

I am aware of a way to find devenv using powershell and extra downloadable packages however this will require writing a PowerShell script, and presumably signing it, and I have no idea whether this will even work in a GitHub Action. Perhaps there is a much simpler approach, hence my question: what is the most direct way to upgrade a solution?

Ross Bencina
  • 3,822
  • 1
  • 19
  • 33

2 Answers2

2

You need a Windows-based runner. vswhere is the tool to get path to various components of the Visual Studio installation and its folder is in the path (source).

run: |
  $devenv = & vswhere.exe '-property' productPath
  Start-Process -FilePath $devenv -ArgumentList '${{env.SOLUTION_FILE_PATH}} /Upgrade' -Wait
riQQ
  • 9,878
  • 7
  • 49
  • 66
  • Does this solution actually work for you? For me I think the step exits before the asynchronous devenv process has finished updating the solution. – Ross Bencina Dec 17 '20 at 06:27
0

Thanks to @riQQ's partial answer I currently have the following, which waits for the output to be done using both a pipe to Out-Null suggested in this answer and also waits for the generated files to appear. Note that I am using a path to the project not to the solution. (I could not get solution upgrading to work correctly, although I never worked out why.)

run: |
    $devenv = & vswhere.exe '-property' productPath
    Write-Output "$devenv"
    & $devenv "${{env.VCPROJ_FILE_PATH}}" /Upgrade /NoSplash | Out-Null
    Write-Output "devenv launched"
    while (!(Test-Path "${{env.VCXPROJ_FILE_PATH}}")) { Start-Sleep -Seconds 10 }
    Write-Output "vcxproj found"
    while (!(Test-Path "${{env.VCXPROJ_FILTERS_FILE_PATH}}")) { Start-Sleep -Seconds 10 }
    Write-Output "vcxproj.filters found"
    Start-Sleep -Seconds 10
    Write-Output "done."

For some reason this step is taking over 5 minutes to complete when run as part of a GitHub Action. It takes only a few seconds on my local machine. Because of the nasty file polling I don't consider this an ideal solution, but I am posting it here for reference.

Ross Bencina
  • 3,822
  • 1
  • 19
  • 33
  • 1
    The slow `devenv.exe` may be due to this GitHub actions issue: https://github.com/actions/virtual-environments/issues/128 – Ross Bencina Dec 17 '20 at 11:49