How to use vcvars64.bat from Powershell?
Hello,
I'd like to be able to use the Visual C++ toolset (cl.exe etc) for generating nmake makefiles with our CMake setup. The only support page I found (https://www.appveyor.com/docs/lang/cpp/) has a solution that does not work for Powershell build scripts. Is there any way to "source" the batch file from within Powershell? Or do I have to migrate my whole build script to be cmd.exe and not PS?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ilya Finkelshte... on 28 Mar, 2018 10:30 PM
Hi Tyler,
Not sure if I understand the problem correctly. Running PowerShell scripts is fully supported in build process: https://www.appveyor.com/docs/build-configuration/#script-blocks-in...
Ilya.
2 Posted by Tyler Denniston on 29 Mar, 2018 12:26 PM
Hi Ilya,
Thanks for the reply. I actually am only using PowerShell for my build script blocks, which I think is part of my problem. Because my build scripts are run in PowerShell, I can't directly follow the instructions from https://www.appveyor.com/docs/lang/cpp/, because
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
is a batch command, not a PowerShell command.I have tried
& "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
andStart-Process "cmd.exe /c C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
but these do not work, as the environment variables set byvcvars64.bat
are not inherited by the PowerShell session. For example, after executing either of those in PowerShell, thecl.exe
,link.exe
and other binaries are still not in the shell's PATH.Essentially I am asking: is there a PowerShell equivalent of
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
?Support Staff 3 Posted by Feodor Fitsner on 29 Mar, 2018 03:27 PM
Right, if you run .cmd from PowerShell its environment variables won't be imported.
To workaround that I'd propose a little "hack".
set > %temp%\vcvars.txt
command to the end ofvcvars64.bat
, something like:Call
vcvars64.bat
from PowerShell.Import variables from
vcvars.txt
:I haven't tested this solution - it's just an idea, but you can give it a try.
4 Posted by Tyler Denniston on 29 Mar, 2018 04:10 PM
Thanks, with your help and https://stackoverflow.com/q/2124753 I got something that seems to work. I added this to my PS build script:
Support Staff 5 Posted by Feodor Fitsner on 29 Mar, 2018 04:14 PM
Yep, that's much nicer solution. Thanks for sharing that.
Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:27 AM.