0

I do something wrong but I do not know what. I have a PowerShell script, where I have a variable like this:

$VCVARSALLBAT = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"

Now, in this script I want to call this vcvarsall.bat doing this:

& "$($VCVARSALLBAT)" x86_amd64

From the output I see, it ran. After calling vcvarsall.bat, I call nmake.

I.e. my script looks like this:

$VCVARSALLBAT = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
& "$($VCVARSALLBAT)" x86_amd64
nmake

I get this error message:

nmake : The term 'nmake' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At ...:214 char:1
+ nmake
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (nmake:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

The odd thing is this: When I go into normal command line of Windows and calling the following statements, I can call nmake without errors:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
nmake
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
devopsfun
  • 1,368
  • 2
  • 15
  • 37
  • Are you running x64 PowerShell or x86? My guess is that your are running 64 bit when you want to be running 32bit. – Matt Apr 24 '18 at 16:31

1 Answers1

3

If nmake is a program, try nmake.exe. nmake.exe needs to be in your path for this to work. If it isn't, you can (a) specifying the full path to the executable (b) or add the executable to your path. You can see if the executable is in your path by calling where.exe nmake from a Powershell or CMD prompt.

ADDED TO ANSWER

Here's what where.exe does...

enter image description here

If you find something in CMD but not Powershell, I'd verify your paths match:

enter image description here

If the given program is in your path, where.exe will find it, even in Powershell.

enter image description here

To the original post, you were getting the standard, "I can't find your command." exception from Powershell:

enter image description here

If you really want to test whether you can call the exe from Powershell, call it explicitly:

'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.13.26128\bin\Hostx86\x86\nmake.exe'

If that works and you want to call it by program name, double check your path.

Adam
  • 3,891
  • 3
  • 19
  • 42
  • I tried `nmake.exe`, but I still get the same error. Calling `& "$($VCVARSALLBAT)" x86_amd64` in my case in Powershell should set the path to `nmake.exe`, but Powershell does not recignize it. – devopsfun Apr 24 '18 at 14:06
  • Did you use ```where.exe``` to see if ```nmake.exe``` is in your path? – Adam Apr 24 '18 at 14:10
  • In command line I get this `C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.13.26128\bin\Hostx86\x86\nmake.exe`. In Powershell nothing. – devopsfun Apr 24 '18 at 14:13
  • 1
    If the purpose of the batch file is to populate environment variables, then you can't just run it from PowerShell. (This is because PowerShell executes the script using `cmd.exe`, but when `cmd.exe` terminates, the variables are disposed.) See answer in duplicate link for a PowerShell function that works around this. – Bill_Stewart Apr 24 '18 at 15:23
  • 1
    Visual Studio comes with several batch files of this type. You can't execute them directly in PowerShell and have the environment variables persist. The function I wrote (link in comment on question) works around this limitation. – Bill_Stewart Apr 24 '18 at 18:03
  • Updated answer. – Adam Apr 24 '18 at 21:29
  • Good information, but unfortunately doesn't help with the stated problem. The documented means for working with the VS tools is to run the batch files to set the needed environment variables (hence my answer in the duplicate link). – Bill_Stewart Apr 24 '18 at 23:35
  • @Bill_Stewart, there is no dispute about the quality of your answer. The update qualifies concerns around calling of executable in Powershell and the use of where.exe. To be blunt, no one is disputing that setting variables through a DOS batch script makes those values available through their containing Powershell session. – Adam Apr 25 '18 at 12:21
  • 1
    I think you may be misunderstanding. Simply adding the `nmake.exe` directory to the `Path` variable isn't going to help, because the VS batch scripts set a group of other related environment variables that all have to be set for command-line builds to work. – Bill_Stewart Apr 25 '18 at 15:28