{"id":92,"date":"2007-01-03T22:29:16","date_gmt":"2007-01-03T21:29:16","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/?p=92"},"modified":"2007-01-03T22:29:16","modified_gmt":"2007-01-03T21:29:16","slug":"using-msbuild-from-the-command-line","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/92-using-msbuild-from-the-command-line.html","title":{"rendered":"Using MSBuild from the command line"},"content":{"rendered":"<p>Now that the holidays are over, here&#8217;s some hardcore tweakery for Visual Studio 2005 developers. Visual Studio 2005 includes a completely new build system based on XML build files and a standalone build utility called MSBuild. Visual Studio project files are in fact MSBuild files. Open them up in a text editor and you&#8217;ll see that they begin like this:<\/p>\n<blockquote>\n<p>&lt;Project DefaultTargets=&#8221;Build&#8221; xmlns=&#8221;<a href=\"http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003&quot;\">http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003&#8243;<\/a>&gt;<\/p>\n<\/blockquote>\n<p>You can also build entire solutions from the command line. Just open up a Visual Studio 2005 command prompt (an easy way of setting up the correct path and enviromental variables), navigate to the project directory, and type:<\/p>\n<blockquote>\n<p>msbuild yourapp.sln<\/p>\n<\/blockquote>\n<p>This is NOT dependent on Visual Studio, since&nbsp;MSBuild is actually part of the .NET Framework redistributable package. This means you can take your project files and build them on machines that don&#8217;t have Visual Studio installed, which can be handy for servers.<\/p>\n<p>But what if you want to edit the solution build file? Curiously, solutions are defined in .sln files which are not msbuild files. When you run MSBuild against an .sln file, it actually creates a new in-memory build file for compilation, making it hard to edit.<\/p>\n<p>This is where the tweak comes in. If you define the enviroment variable msbuildemitsolution, then&nbsp;MSBuild generates the solution build file and leaves it there for you to edit. It is given the name yourapp.sln.proj. For the next build, you can run msbuild against this file directly, thus incorporating any manual changes.<\/p>\n<p>Why it works like this, who knows? Still, it&#8217;s an intriguing tip and as you can guess I didn&#8217;t discover it by accident. I got it from Sayed Ibrahim Hashim&#8217;s <a href=\"http:\/\/www.sedodream.com\/default.aspx\" target=\"_blank\">excellent blog<\/a>. He is the author of the MSBuild\/ClickOnce book <a href=\"http:\/\/www.amazon.com\/exec\/obidos\/ASIN\/1590596528\/itwriting-20\" target=\"_blank\">Deploying .NET applications<\/a>. I haven&#8217;t seen the book, but I recommend the blog if you want to know more about msbuild; the book is likely good as well.<\/p>\n<p><div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:7e467dea-3685-4863-9f59-8a49d43dc410\" contenteditable=\"false\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/msbuild\" rel=\"tag\">msbuild<\/a>, <a href=\"http:\/\/technorati.com\/tags\/visualstudio\" rel=\"tag\">visualstudio<\/a>, <a href=\"http:\/\/technorati.com\/tags\/.net\" rel=\"tag\">.net<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that the holidays are over, here&#8217;s some hardcore tweakery for Visual Studio 2005 developers. Visual Studio 2005 includes a completely new build system based on XML build files and a standalone build utility called MSBuild. Visual Studio project files are in fact MSBuild files. Open them up in a text editor and you&#8217;ll see &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/92-using-msbuild-from-the-command-line.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using MSBuild from the command line<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80,97],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-software-development","category-windows"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}