0

I have been stuck on this for ages. I am trying to run the following command from a .ps1 file

  cmd --% /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" "&&" nuget restore "&&" msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishProfile=ServerFolderProfile

But I keep getting the following error

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

I figured out how to run the command from a PowerShell window from a previous question.

Also, the Stop-Parsing --% symbol requires at least Version 3 of PowerShell and I am running version 5.1.

4
  • 1
    version 5 is over 3 powershell wise so thats ok. CMD is a process for shell. This loks like a mix of shell and powershell. What exactly are you trying to do? Commented Oct 28, 2018 at 20:54
  • @ArcSet I am trying to automate deployment of my ASP.NET project. When I push my branch to a remote repo on my network a git hook (post-receive) executes a PowerShell script (which includes the line above) that builds and deployes the app to a folder. All I really need is msbuild.exe to do this, but when I run it from a regular command prompt I get errors and the solution I found was to use the Developer Command Prompt for Visual Studio. All VsDevCmd.bat from my command does is set some environment variables that the Developer Command Prompt would use. Commented Oct 28, 2018 at 21:26
  • Did you check Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"? Commented Oct 29, 2018 at 0:10
  • @JosefZ While that didn't solve the original questions, using Test-Path did introduce me to a new problem I have to solve. The bat file is on my server, and if I run PowerShell from my local machine from a shared folder on my server, then Test-Path fails because it is looking on my local machine. So now I have to figure out how to get the Script to remote into my server, because when I run Test-Path directly on my server it passes. Commented Oct 29, 2018 at 3:59

1 Answer 1

1

Forget about --%. Put quotes around the entire commandline you want to run in CMD and escape the nested double quotes around the path to the batch file.

cmd /c "`"C:\Pro...Cmd.bat`" && nuget restore && msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishProfile=ServerFolderProfile"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Worked like a charm. Of course now I am running into some other problems with my script but at least I got this solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.