Building Visual Studio solutions using msbuild in cygwin

I use cygwin extensively and hate switching over to Visual Studio Command Prompt just to be able to use msbuild. I figured out how I can invoke msbuild from cygwin. It’s a neat and easy solution, but I am sure a better solution exists.

Steps to follow:

1. Create a file called vs [See Note 1]

2. Copy and paste the following line in the file:

cmd /k “C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat” x86

3. Save the file under /usr/bin. [See Note 2]

4. Make sure the file is executable. Execute the command

chmod +x vs

You are done.

Test it:

1. Open up cygwin and execute the file.

   cygwin> vs

It will display this message and give you a VS command prompt:

Setting environment for using Microsoft Visual Studio 2005 x86 tools

Note 1: You can use a different name for the file. I named it vs for visual studio.

Note 2: You can put it under any directory you like. If you decide to put it under any other directory, then you you have two options:
1. Add that directory to PATH. OR
2. Give the full path to the directory whenever you execute this file.

Note 3: For some reason the UP key does not work. I need to find a fix for this.

Note 4: I know a better solution exists. The batch file which I execute in the vs file is setting a few environment variables. Instead of invoking this batch file, I should set the environment variables directly. This is a neater solution.


3 thoughts on “Building Visual Studio solutions using msbuild in cygwin

  1. Mangesh Ghiware says:

    If you launch cygwin using a shortcut to cygwin.bat, you can add the following to cygwin.bat:

    call “C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat” x86

    Another approach is to save the following in a file, say vs2005, and source it from your .bashrc. You can then use msbuild even when you logged in through ssh.

    $ cat ~/.bash/vs2005
    # translate
    # ‘C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat’
    # into bash commands

    msdev=’C:\Program Files\Microsoft Visual Studio 8′
    export VSINSTALLDIR=$msdev
    export VCINSTALLDIR=$msdev\\VC
    export FrameworkDir=’C:\WINDOWS\Microsoft.NET\Framework’
    export FrameworkVersion=v2.0.50727
    export FrameworkSDKDir=$msdev\\SDK\\v2.0

    # Root of Visual Studio IDE installed files.
    export DevEnvDir=$msdev\\Common7\\IDE

    DevEnvDir_UNIX=$(cygpath –unix “$DevEnvDir”)
    FrameworkDir_UNIX=$(cygpath –unix “$FrameworkDir”)
    FrameworkSDKDir_UNIX=$(cygpath –unix “$FrameworkSDKDir”)

    TOOLSDIR_UNIX=$(cygpath –unix “$msdev\\Common7\\Tools”)


    export LIB=$VCINSTALLDIR\\ATLMFC\\LIB’;’$VCINSTALLDIR\\LIB’;’$VCINSTALLDIR\\PlatformSDK\\lib’;’$FrameworkSDKDir\\lib
    export LIBPATH=$FrameworkDir\\$FrameworkVersion’;’$VCINSTALLDIR\\ATLMFC\\LIB

    unset msdev
    unset DevEnvDir_UNIX
    unset FrameworkDir_UNIX
    unset FrameworkSDKDir_UNIX

    $ cat ~/.bashrc
    if [ -n “$PS1” ]; then
    # source MS VS 2005 settings
    source ~/.bash/vs2005

    # snipped rest of the file


  2. Mangesh Ghiware says:

    Forgot to credit Mark Hadfield (see

  3. generally says:

    Thanks for the much neater solution, Mangesh.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: