53

I want to create a batch file for Visual Studio 2008 x64 Cross Tools Command Prompt to do something continuesly in my PC, here is the senario.

svn update
delete some files
MSBuild MySolutiuon.sln
delete some files
xcopy somefiles
MSBuild AutomateBuildConfiguration.xml /p:Configuration=Release
xcopy some files
delete somefiles
xcopy some files

create a Zip file if it is possible // it is not neccessary

I can do most of it with simple Command Prompt and MSBuild parts with Visual Studio Command Prompt, but as these two prompt are different I cannot complete my senario.

I have tested all command and work great for me, Give me a solution if you know what should I do.

I checked this and didn't underestand anything Thank you in advance

Community
  • 1
  • 1
Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100

7 Answers7

89

Make the first line of your batch file set up the VS environment:

call "C:\Program Files\Microsoft Visual Studio 2008\VC\vcvarsall.bat" x86_amd64
svn update
delete some files
MSBuild MySolutiuon.sln
... more commands ...

x86_amd64 is the argument used for x64 Cross Tools Command Prompt.

Once vcvarsall.bat has run, msbuild will be available in the path for the rest of the commands in your batch file.

Alternatively, if you aren't using Visual C++, you might prefer to set up the environment with this line (instead of the call to vcvarsall.bat):

For VS 2008:

call "%vs90comntools%vsvars32.bat"

For VS 2010:

call "%vs100comntools%vsvars32.bat"

For VS 2012:

call "%vs110comntools%vsvars32.bat"

For VS 2013:

call "%vs120comntools%vsvars32.bat"

For VS 2015:

call "%vs140comntools%vsvars32.bat"

For VS 2017:

Batch is now called vc not vs.

call "%vs140comntools%\..\..\VC\Auxiliary\Build\vcvars32.bat"

or better

call "%vs140comntools%\VsDevCmd.bat"
Tomasz Juszczak
  • 2,276
  • 15
  • 25
sean e
  • 11,792
  • 3
  • 44
  • 56
  • 1
    I'm not sure that MSBuild command will run correctly. and actually I have to have a single batch file. it will use as my in-house continues integration tool at night, so that I can not run them my self. – Nasser Hadjloo May 04 '11 at 05:50
  • I mean I'm not sure with this trick MSBuild will detect as an internal comand, because it is running withing simple Command prompt, doesn't it? How to do this (tun my batch file with VS prompt)? – Nasser Hadjloo May 04 '11 at 05:57
  • +1'd. Although I couldnt find an equivalant cmd environment variable for VS2010; "call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" works for me. – Christo Jul 30 '12 at 01:59
  • 3
    This works for vs12 as well. Command for me is: call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64 If you go to the vcvarsall.bat file, right click, edit, you can see all the different commands. – thed0ctor Dec 19 '12 at 18:57
  • 2
    There is environmental variable `VS120COMNTOOLS` (120 means Vs 2013; VS 2012 would be 110 and so forth). Using it allows to avoid hardcoding the path to the VS installation. – Violet Giraffe Jan 14 '15 at 15:10
  • Looks like the environment variable for VS2017 should be %vs150comntools%, not %vs140comntools% ? – Jeremy Friesner Jun 20 '18 at 20:55
21

For Visual Studio 2015:

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64

For Visual Studio 2013:

call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64
Michael Sander
  • 2,677
  • 23
  • 29
4

For Visual Studio 2010, this is working great:

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Shanerk
  • 5,175
  • 2
  • 40
  • 36
4

For Visual Studio 2019 :

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
user2226755
  • 12,494
  • 5
  • 50
  • 73
  • 1
    I don't have this path. Am I missing something? Thanks! – user840718 Dec 10 '19 at 00:44
  • Thanks! I had trouble finding the correct path. Since I have VS 2019 Professional I just replaced "Community" with "Professional". I would assume you would replace it with Enterprise if you have Enterprise. – Joe Gayetty May 29 '20 at 17:49
  • 1
    This randomly breaks for me when I execute the batch file multiple times from the same instance of cmd.exe. Somehow this makes changes to the environment which persist after the batch execution has finished. Also I have to ask how this is different from `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat` which is being run by the default Start Menu entry for the Developer Command Prompt. – Zyl Jun 21 '20 at 19:33
2

And for Visual Studio 2012:

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
Good Samaritan
  • 706
  • 1
  • 7
  • 21
1

I wrote a bat file using the following steps and it worked.

call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64
echo call complete
pause
cd C:\tfs.sbdinc.com
tf get $/MAC_MBA/CoreApplicationAndReports/Main/Application/Solution /recursive
echo get complete
pause
cd C:\tfs\CoreApplicationAndReports\Main\Application\Solution
msbuild
echo build complete
pause
devenv mba.sln
echo ide launch complete
pause
sam
  • 320
  • 3
  • 14
1

Try below batch file to run the MS test/Nunit test for C# tests.

@echo off
echo Run the CMD(Command Prompt) Program.
echo.
pause
cls
echo Target Framwork
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
echo 'Project Path'
msbuild  "C:\Git\ElementsCloud.Tests\Source\ElementsCloud.Tests.sln"/p:configuration=debug
pause
echo 'Project Dll path' and Execute tests
cd C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow
vstest.console.exe "C:\Git\ElementsCloud.Tests\Source\Selenium.Tests\bin\Debug\net471\Selenium.Tests.dll" /Tests:Test1,Test2,Test3
echo. 
PAUSE
EXIT
  • What does the EXIT do at the end? Does it just exit the build tools or the whole command prompt? – Heather Aug 29 '19 at 10:07