<p>How do you turn a Visual Studio build that you'd perform in the IDE into a script that you can run from the command line?</p>

[{'answer_id': 24581, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 2, 'selected': False, 'text': '<p>Look into  build tool <a href="http://en.wikipedia.org/wiki/NAnt" rel="nofollow noreferrer">NAnt</a> or <a href="http://en.wikipedia.org/wiki/MSBuild" rel="nofollow noreferrer">MSBuild</a>. I believe MSBuild is the build tool for Visual&nbsp;Studio&nbsp;2005 and later. I am, however, a fan of NAnt...</p>\n'}, {'answer_id': 24583, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 2, 'selected': False, 'text': '<p>Simplest way: navigate to the directory containing the solution or project file, and run <code>msbuild</code> (assuming you have Visual Studio 2005 or newer).</p>\n\n<p>More flexible ways:</p>\n\n<ul>\n<li>Read up on <a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx" rel="nofollow noreferrer">the MSBuild\nreference</a>. There are tons of\ncustomization, especially once\nyou\'ve installed the <a href="https://github.com/loresoft/msbuildtasks" rel="nofollow noreferrer">MSBuild Community Tasks Project</a>.  </li>\n<li>Use <a href="http://en.wikipedia.org/wiki/NAnt" rel="nofollow noreferrer">NAnt</a>. It has existed\nfor longer than MSBuild and has more\ncommunity support, but requires you\nto start a project file from\nscratch, rather than extending the\nexisting, Visual Studio-created one.</li>\n</ul>\n'}, {'answer_id': 24584, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 5, 'selected': False, 'text': '<pre><code>\\Windows\\Microsoft.NET\\Framework\\[YOUR .NET VERSION]\\msbuild.exe\n</code></pre>\n\n<p>Lots of command line parameters, but the simplest is just:</p>\n\n<pre><code>msbuild.exe yoursln.sln\n</code></pre>\n'}, {'answer_id': 24591, 'author': 'alanl', 'author_id': 1464, 'author_profile': 'https://Stackoverflow.com/users/1464', 'pm_score': 2, 'selected': False, 'text': '<p><strong><a href="http://en.wikipedia.org/wiki/NAnt" rel="nofollow noreferrer">NAnt</a></strong> and <strong><a href="http://en.wikipedia.org/wiki/MSBuild" rel="nofollow noreferrer">MSBuild</a></strong> are the most popular tools to automate your build in <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="nofollow noreferrer">.NET</a>, and you can find a discussion on there of the pros/cons of each in the Stack Overflow question <em><a href="https://stackoverflow.com/questions/16550">Best .NET build tool</a></em>.</p>\n'}, {'answer_id': 24601, 'author': 'Sam Hasler', 'author_id': 2541, 'author_profile': 'https://Stackoverflow.com/users/2541', 'pm_score': 1, 'selected': False, 'text': '<p>I had to do this for a C++ project in Visual Studio <strong>2003</strong> so I don\'t know how relevant this is to later version of visual studio:</p>\n\n<p>In the directory where your executable is created there will be a <code>BuildLog.htm</code> file. Open that file in your browser and then for each section such as:</p>\n\n<pre><code>Creating temporary file "c:\\some\\path\\RSP00003C.rsp" with contents\n[\n/D "WIN32" /D "_WINDOWS" /D "STRICT" /D "NDEBUG" ..... (lots of other switches)\n.\\Project.cpp\n.\\Another.cpp\n.\\AndAnother.cpp\n".\\And Yet Another.cpp"\n]\nCreating command line "cl.exe @c:\\some\\path\\RSP00003C.rsp /nologo"\n</code></pre>\n\n<p>create a .rsp file with the content between the square brackets (but not including the square brackets) and call it whatever you like. I seem to remember having problems with absolute paths so you may have to make sure all the paths are relative.</p>\n\n<p>Then in your build script add the command line from the <code>BuildLog.htm</code> file but with your .rsp filename:</p>\n\n<pre><code>cl.exe @autobuild01.rsp /nologo\n</code></pre>\n\n<p>(note there will also be a link.exe section as well as cl.exe)</p>\n'}, {'answer_id': 32827, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 2, 'selected': False, 'text': '<p>As of <a href="http://en.wikipedia.org/wiki/Microsoft_Visual_Studio#Visual_Studio_2005" rel="nofollow noreferrer">Visual&nbsp;Studio&nbsp;2005</a>, all of the project files (at least for .NET based projects) are actual <a href="http://en.wikipedia.org/wiki/MSBuild" rel="nofollow noreferrer">MSBuild</a> files, so you can call MSBuild on the command line and pass it the project file.</p>\n\n<p>The bottom line is that you need to use a "build scripting language" like <a href="http://en.wikipedia.org/wiki/NAnt" rel="nofollow noreferrer">NAnt</a> or MSBuild (there are others, but these are the mainstream ones right now) if you want to have any real control over your build process.</p>\n'}, {'answer_id': 34063, 'author': 'Agnel Kurian', 'author_id': 45603, 'author_profile': 'https://Stackoverflow.com/users/45603', 'pm_score': 6, 'selected': True, 'text': '<p>With VS2008 you can do this:</p>\n\n<pre><code>devenv solution.sln /build configuration\n</code></pre>\n'}, {'answer_id': 873153, 'author': 'ferventcoder', 'author_id': 18475, 'author_profile': 'https://Stackoverflow.com/users/18475', 'pm_score': 2, 'selected': False, 'text': '<p>Take a look at UppercuT. It has a lot of bang for your buck and it does what you are looking for and much more.</p>\n\n<p>UppercuT uses NAnt to build and it is the insanely easy to use Build Framework.</p>\n\n<p>Automated Builds as easy as (1) solution name, (2) source control path, (3) company name for most projects!</p>\n\n<p><a href="http://projectuppercut.org" rel="nofollow noreferrer">http://projectuppercut.org/</a></p>\n\n<p>Some good explanations here: <a href="http://ferventcoder.com/category/uppercut.aspx" rel="nofollow noreferrer">UppercuT</a></p>\n'}, {'answer_id': 16248370, 'author': 'GSoft Consulting', 'author_id': 305197, 'author_profile': 'https://Stackoverflow.com/users/305197', 'pm_score': 2, 'selected': False, 'text': '<p>Here is my batch file using <strong>msbuild</strong> for VS <strong>2010</strong> Debug configuration:</p>\n\n<pre><code>"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe" \niTegra.Web.sln /p:Configuration=Debug /clp:Summary /nologo\n</code></pre>\n'}, {'answer_id': 27001741, 'author': 'rboy', 'author_id': 2280961, 'author_profile': 'https://Stackoverflow.com/users/2280961', 'pm_score': 2, 'selected': False, 'text': '<p>Here is the script I\'m using to completely automate the command line build of x86 AND x64 configurations for the same solution through batch scripts.</p>\n\n<p>This is based on DevEnv.exe as it works if you have a Setup project in your build (msbuild doesn\'t support building Setup projects).</p>\n\n<p>I\'m assuming your setup is 32bit Windows 7 with Visual Studio 2010 setup using the x86 native compiler and x64 cross compiler.\nIf you\'re running 64bit windows you may need to change <em>x86_amd64</em> to <em>amd64</em> in the batch script depending on your setup.\nThis is assuming Visual Studio is installed in <em>Program Files</em> and your solution is located in <em>D:\\MySoln</em></p>\n\n<p>Create a file called <em>buildall.bat</em> and add this to it:</p>\n\n<pre><code>D:\ncd "D:\\MySoln"\n\nif "%1" == "" goto all\nif %1 == x86 goto x86\nif %1 == x64 goto x64\n\n:x86\n%comspec% /k ""C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat"" x86 &lt; crosscompilex86.bat\ngoto eof\n\n:x64\n%comspec% /k ""C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat"" x86_amd64 &lt; crosscompilex64.bat\ngoto eof\n\n:all\n%comspec% /k ""C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat"" x86 &lt; crosscompilex86.bat\nif %ERRORLEVEL% NEQ 0 goto eof\n%comspec% /k ""C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\vcvarsall.bat"" x86_amd64 &lt; crosscompilex64.bat\ngoto eof\n\n:eof\npause\n</code></pre>\n\n<p>Now create 2 more batch scripts:</p>\n\n<p><em>crosscompilex86.bat</em> to build the Release version of a x86 build and include this</p>\n\n<pre><code>devenv MySoln.sln /clean "Release|x86"\nIF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%\ndevenv MySoln.sln /rebuild "Release|x86"\nIF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%\n</code></pre>\n\n<p><em>crosscompilex64.bat</em> to build the Release version of the x64 build and include this</p>\n\n<pre><code>devenv MySoln.sln /clean "Release|x64"\nIF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%\ndevenv MySoln.sln /rebuild "Release|x64"\nIF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%\n</code></pre>\n\n<p>Now place all 3 batch files along in your solution folder along with MySoln.sln.\nYou can build both x86 and x64 Release versions by creating a Shortcut on your desktop which run the following commands:</p>\n\n<ul>\n<li>Build All -> <em>D:\\MySoln\\buildall.bat</em></li>\n<li>Build x86 Release Only -> <em>D:\\MySoln\\buildall.bat x86</em></li>\n<li>Build x64 Release Only -> <em>D:\\MySoln\\buildall.bat x64</em></li>\n</ul>\n\n<p>If you\'re using another configuration like AnyCPU etc you would need to customize the above scripts accordingly.</p>\n'}, {'answer_id': 41894511, 'author': 'A. Lyoussi', 'author_id': 5303309, 'author_profile': 'https://Stackoverflow.com/users/5303309', 'pm_score': -1, 'selected': False, 'text': '<p>A more simple way is to change VS 2015 Projects &amp; Solutions configuration:\nGo to the Tools tab -> Options -> Projects and Solutions -> Build and Run -> On Run, when projects are out of date (choose Always build). VOILA! </p>\n\n<p>Now your IDE will automatically build your project when you run (F5) it. Hope this helps, any feedback are welcome.</p>\n'}]
['https://Stackoverflow.com/questions/24580', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2541/']