How to execute VS2013 MSBuild from an EXISTING command prompt - shell

I would like to "MSBuild" (VS2013) my application as part of a bigger ".cmd" script. I cannot let visual studio build a shell and issue commands into that shell (please don't ask why; if that were negotiable I wouldn't have to ask this question in the first place)
I have the shell, its path, and its environment variables prepared for everything else (except Visual Studio 2013 and MSBuild). What can I do or invoke, so that the next command then can be "MSBuild..."
I have spent hours searching in vain but all I have found looks to me like it requires building a new shell, applying a mouse click, or loosing the standard input.
Thanks

Run vsvars32.bat. It is in the Common7\Tools folder of your Visual Studio installation. In the case of VS 2013, this folder is available in the environment variable, VS120COMNTOOLS. It is similar for other versions of VS. Your script will be something like:
call "%VS120COMNTOOLS%vsvars32.bat"
msbuild mysolution.sln /t:Build

Related

How to add batch file in windows environment variable

I am following the installation guide for openvino on Windows. After a successful installation, we need to run setupvars.bat file in order to initialize the openvino environment. We can also add it permanently in environment variable so that it is initialized automatically. But the instructions are not given on how to add it.
I wanted to know if its possible to add the setupvars.bat so the it runs automatically. Also I need to run the visual studio from the same environment.
I always do this step manually which takes a lot time. I first open a cmd, navigate to the desired folder and then run setupvars.bat. After that from the same cmd, I navigate to the visual studio installed directory and then start the visual studio from the cmd so that visual studio is launched under same openvino environment. Is is possible to automate all this task. Thanks
Solution 1: You can set the environment variables for the visual studio as mentioned here - How do I set specific environment variables when debugging in Visual Studio?
Solution 2: Write one more batch file which will 1st call setupvars.bat & then open the visual studio. Then you can run the new bat file.
Solution 3: You can create a cmd shortcut like this - Run a Command Prompt command from Desktop Shortcut
In this, you can 1st call setupvars.bat and then cmd to open Visual Studio. Once you click the new shortcut both the things should happen automatically. You can even add this step along with the installer.

Obtain visual studio generated build command

I want to create a batch file for building releases of a multi-solution software. What I am curious about how may I obtain the exact MSBuild command that Visual Studio executes when I click on "Rebuild Solution"?
It is equivalent to
MsBuild /t:Rebuild /p:Configuration=<config>;Platform=<platform>
although VS actually generates a temporary msbuild file from the solution and then builds that. You get the file by setting an MSBuildEmitSolution environment variable:
open a VS command window
enter set MSBuildEmitSolution=1
enter devenv to open a VS instance within that command window so it uses the MSBuildEmitSolution environment variable
open and build your solution

Platform toolset (v110) is not installed or invalid

I have a weird problem when I want to compile a Visual Studio 2012 solution via msbuild on the command line. Whatever I do, it exits with Specified platform toolset (v110) is not installed or invalid. I have tried launching it via the regular command prompt, the Windows 7 SDK prompt, and all three command prompts included in VS2012. However, compiling in Visual Studio itself works.
where msbuild outputs:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
c:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe
You have probably solved the problem yourself but perhaps it may help others with a similar problem. Try to set the VisualStudioVersion environment variable before running MSBuild, e.g
SET VisualStudioVersion=11.0
There is a possibility that it helps.
You could also try passing the command line parameter /p:VisualStudioVersion=11.0 to MSBuild, when trying to build your project. It seems to have the same effect as setting the environment variable, in the above answer.

Batch Builds in Visual Studio 6 for VC++ project

In VS 2008 and VS 2010, one can easily create a solution and modify the "Solution Configuration". We can choose what configuration each project gets built in when we trigger a build at the solution level.
Is such a facility available in the Visual Studio 6.0?
In my experience:
when a configuration is chosen (form the list available) in VS6 for a VC++ project, the dependencies (which themselves have multiple configurations defined) get built in some random order. There is no way to control the configurations of dependencies at build time.
"Batch Build" does come close to this but is not as flexible for my purpose.
I have tried various options in the VS6.
Hope I am clear.
Here is a link on the MSDEV command line.
https://msdn.microsoft.com/en-us/library/aa699274(v=vs.60).aspx
There is a way to control the building of dependencies. Specify /NORECURSE and dependencies will not be built.
I use /REBUILD with /NORECURSE to keep the dependencies from getting built.
And I build each project one at a time inside the workspace in a bat file by doing a chdir to the subdirectory and calling MSDEV just for that subproject:
msdev myproject.dsp /MAKE "myproject - Win32 Debug" /REBUILD /NORECURSE > Build.log
Then I cd to the next project directory one at a time.
On a side note, I had difficulties for several years where NMAKE would not work for my specific tasks. Turns out that the PATH environment variable inside MSDEV (Visual Studio 6.0) is different from the PATH environment variable of a command shell you would run NMAKE on.
The Path used by the MSDEV shell is the %PATH% at the time Visual Studio 6 was installed. We use this and poke the registry as needed for MSDEV to get the correct path setup when switching revisions of our software; however this doesn't help update the %PATH%. The MSDEV path can be queried with a query script. I don't have my example handy.
That is why builds in MSDEV sometimes work when builds using the command line don't, as the path to DLLs differ, and any custom build steps that run .exe will not work outside of the MSDEV environment unless the path is updated.
I have a script somewhere that reads the queries the registry to extract the MSDEV path and update PATH of a shell so that batch scripts doing nmake will work as they would inside the MSDEV shell environment. The problem with the REGISTRY QUERY is that the return arguments differ with different flavors of Windows (XP/SERVER2003/...).
One thing I just discovered is that Incredibuild works with the old VS6.0 MSDEV IDE. This is a game changer. It distributes builds. I'm evaluating it now, but it might be useful to anyone waiting for long VS6.0 builds.

Env vars for Visual Studio command prompt

I'm doing an RDP into a machine that has just the CLR installed, and doesn't have Visual Studio on it. Can I somehow load all the Visual Studio-specific environment variables on to the regular command prompt and convert it into the VS command prompt so that I'm able to build my projects via command line?
I looked at the vcvarsall.bat file. That calls the appropriate processor-specific batch file. Couldn't get any inputs from there.
Short of installing all VS, or tracing thru all the various batch files to find out what's getting set, you may be able to simply capture the env vars that are set.
Open up a VS command prompt, and run set > vars.bat
Then open up vars.bat, and put a set command in front of each line.
Not sure how much this will help, since you're going to be missing all the utilities that come with Visual Studio, but it does answer your question.
I don't recommend trying to copy only what you need. You'll need other header files, libraries, dlls, etc... You can instead install VS express edition.
If you are trying to debug a problem you can use remote debugging in Visual Studio or use WinDbg on the computer.

Resources