{"id":163,"date":"2016-01-21T22:02:53","date_gmt":"2016-01-21T21:02:53","guid":{"rendered":"http:\/\/www.vosseburcht.com\/?p=163"},"modified":"2016-01-21T22:02:53","modified_gmt":"2016-01-21T21:02:53","slug":"msbuild-command-line-building-a-single-project-from-a-solution","status":"publish","type":"post","link":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/2016\/01\/21\/msbuild-command-line-building-a-single-project-from-a-solution\/","title":{"rendered":"MSBuild command line building a single project from a solution."},"content":{"rendered":"<p>I recently needed to build just one project (and its dependencies) from a solution. I quickly found the following MSDN article on exactly how to do this:<\/p>\n<p>https:\/\/msdn.microsoft.com\/en-us\/library\/ms171486.aspx<\/p>\n<p>However, I couldn&#8217;t get it to work for the life of me. The command always complained along the lines of:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">MySolution.sln.metaproj : error MSB4057: The target \"My.Project:Clean\" does not exist in the project. [MySolution.sln]<\/pre>\n<p>Luckily during a search on the internet about troubleshooting MSBuild issues, I came across a way to save the intermediate project file created by MSBuild from the solution. Because as you might have noticed when you look at a .sln file, its not even close to a regular MSBuild project file. MSBuild interprets the solution file and generates one big MSBuild project file from it, then builds that file.<\/p>\n<p>This can be done by setting an environment variable before calling the MSBuild for a solution. In a command prompt type the following:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Set MSBuildEmitSolution=1<\/pre>\n<p>When you then for instance build a solution with the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">msbuild MySolution.sln \/t:Clean<\/pre>\n<p>This will perform a clean of the solution, but also save the entire MSBuild project file in a file called MySolution.sln.metaproj.<\/p>\n<p>I thought this was a good idea because the MSDN article above talks about targets, and usually targets in a project file are called Clean, or Rebuild or something like that. Why would there be a target &#8220;MyProjectName:Clean&#8221;? Well, because MSBuild generate that target in the aforementioned .metaproj file.<\/p>\n<p>It turns out however that target names may not contain the . character. And MSBuild nicely works around this by replacing them with _ characters. So to get my single project building I had to call:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">msbuild MySolution.sln \/t:My_Project:Rebuild<\/pre>\n<p>Hopefully this post saves someone else some time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to build just one project (and its dependencies) from a solution. I quickly found the following MSDN article on exactly how to do this: https:\/\/msdn.microsoft.com\/en-us\/library\/ms171486.aspx However, I couldn&#8217;t get it to work for the life of me. The command always complained along the lines of: MySolution.sln.metaproj : error MSB4057: The target &#8220;My.Project:Clean&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/163"}],"collection":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":0,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"wp:attachment":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}