I'm writing a powershell script that remotely gets the workspace info on a remote computer's TFS.
What I need to do is either invoke-command or psexec the path of the batch file to open up the visual studio dev command prompt, and then run a command inside that prompt. What I'm having trouble with is executing the second command inside the dev command prompt. What is happing right now is I'm able to open the dev command prompt, but only when I exit it does the second command run. Below is some code I was trying.
.
Invoke-Command -ComputerName computer1 {cmd /k '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\LaunchDevCmd.bat" & tf'}
^ I get a tf is not recognized, which it isn't when in a normal command prompt. If it ran in the dev prompt I'd get some version info and help commands.
.
#echo off
"C:\Users\me\Downloads\PSTools\PsExec.exe" \\computer1 cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\LaunchDevCmd.bat" & "tf"
^ This opens the dev prompt, and upon exiting it gives an error that tf is not a command.
.
What I want to do is: Normal Prompt > Dev Prompt > Run Command > Leave Both. Is this possible? Is there a way to just start at the dev prompt?
You could invoke tf.exe command in your powershell directly:
PS> & "$env:Program Files (x86)\Microsoft Visual Studio\2017\\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe" #("workspace", "/new", "xxx", "/noprompt", "/login:xxx,xxx", "/collection:xxx")
Related
I want to use PowerShell to run a script that:
Launches Visual Studio Developer Command Prompt (VS 2017)
Enters in sequence of commands to do a batch and release build
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" && <next sequence of commands to do batch build>
The above code simultaneously opens VS Dev prompt and my sequence of commands. There is no pause after opening the prompt, so the commands do not run.
Screenshot of what happens
My primary use case is I'd like to use devenv.exe /edit command to open files in an already running instance of Visual Studio 2019, using git bash.
The issue I'm having is that I cannot seem to finesse git bash to run the command in a way that actually works.
Specifically, this is what I'm seeing:
from windows cmd:
command: devenv /edit foobar.c
results: SUCCESS!; opens foobar.c in an existing instance of visual studio 2019
from git bash:
command: devenv /edit foobar.c
result: FAIL!; opens a new instance of 2019, and has an error popup saying: The following files were specified on the command line: "C:/Program Files/Git/edit" These files could not be found and will not be loaded. Opens file
from git bash, tucking the command under a .bat file
mybat.bat contents: devenv /edit foobar.c
command: cmd //c mybat.bat
result: FAIL!; Opens a new instance of 2019, no error popup, opens file.
from git bash, using full paths to exe and file
command: "/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/devenv.exe" /edit /c/Users/MYNAME/foobar.c
result: FAIL!; opens a new instance of 2019, and has an error popup saying: The following files were specified on the command line: "C:/Program Files/Git/edit" These files could not be found and will not be loaded. Opens file
from git bash, escaping the edit command and and using full paths:
command: "/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/devenv.exe" /edit /c/Users/MYNAME/foobar.c
result: FAIL!; Opens a new instance of 2019, no error popup, opens file.
from git bash, after opening the sln via git bash:
command 1: devenv.exe my_solution.sln &
result: Opens my solution
command 2: devenv.exe //edit foobar.c &
result: SUCCESS!; opens foobar.c in an existing instance of visual studio 2019
Command 3 (from a different git bash): devenv //edit foobar.c &
result: FAIL!; Opens a new instance of 2019, no error popup, opens file.
Can anyone think of a method to invoke the command from git bash, in the same fashion that a windows command prompt (cmd.exe) would invoke the command?
The only solution I could find was to put "& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe" "solution.sln" /Build Release in a .ps1 file and call powershell build.ps1 from my .sh file.
I have a batch file that executes these commands:
set repodir=D:\Folder
cd /d %repodir%
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
tf undo * /recursive /noprompt
tf get
I want to achieve same functionality from shell script. I am able to change the directory path to wherever code is present
Problems:
command call is not found - read that I need to use . operator in shell script. Tried this but not working. Error is "#echo command not found" in vcvarsall.bat ( the first line in that file is #echo off )
. "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
Since calling batch file is failing in step 2, command tf is not found
tf undo * /recursive /noprompt
tf get
Environment: I am trying to run the shell script using cygwin on Windows Server 2008
Remove the 'call' because that is for calling one bat file from another.
Specify the full path for tf.exe. Of course that will vary depending on the version of TFS you have installed.
I want to run a batch script inside of the deployment tools command prompt (part of the Windows AIK) to create a WinPE iso. I went through the steps to prep the media and created a script to navigate to the right directory and then run the oscdimg.exe tool.
The problem is that it runs in a normal command prompt, not the deployment tools command prompt. Is it possible to write a script that will run in the deployment tools command prompt instead of the regular command prompt?
My basic script:
#echo off
#echo Running OSCDIMG to create a WinPE amd64 iso in f:\OtherItems\view_stores\WinPE7\winpe.iso
f:
cd \OtherItems\view_stores\WinPE7
oscdimg.exe -n -bf:\OtherItems\view_stores\WinPE7\etfsboot.com f:\OtherItems\view_stores\WinPE7\ISO f:\OtherItems\view_stores\WinPE7\winpe.iso
#echo **********************************************************************
#echo Done.
#echo
pause
If you look at the Properties of 'Deployment Tools Command Prompt' the target is:
C:\Windows\System32\cmd.exe /k "C:\Program Files\Windows AIK\Tools\PETools\pesetenv.cmd"
So it's not a separate program, it's a batch run in the regular cmd prompt.
You can take the content of "pesetenv.cmd" and use it as a prefix to your batch:
Now the Deployment Tools commands should work as expected.
EDIT:
Scratch the above, I don't know why I thought that was doing something. Adding the full path to oscdimg.exe and imagex.exe is what works for me.
C:\Program Files\Windows AIK\Tools\x86\oscdimg.exe -n -bf:\OtherItems\view_stores\WinPE7\etfsboot.com f:\OtherItems\view_stores\WinPE7\ISO f:\OtherItems\view_stores\WinPE7\winpe.iso
Is there a way to run any command (eg: cd D:\test) on Command Prompt start and to have this instance of Command Prompt as a different shortcut/instance.
You can create a shortcut that has a target of e.g.:
%comspec% /k ""C:\Full_Path_to\VsDevCmd.bat""
Where the .bat file is the command(s) that you want to run on startup. This will then leave you with an open command prompt after those commands have executed.
(In case it's not obvious, this is just shamelessly ripped from one of the Developer Command Prompt shortcuts that Visual Studio installs in the Start Menu)
%comspec% is a nice way of getting cmd to execute.
Cmd:
/k : Carries out the command specified by string and continues.