title: How to get Visual Studio build process to create a distributable directory?
body: <p>I would like to customize my Visual Studio Solution build to automatically create a directory tree with dist -> bin directories.  The bin directory should have all binaries automatically copied to it. </p>
  
  <p>Note: the solution has many projects so I do not want to customize the project build, this should be on the solution level.</p>
  
  <p>I have already tried 2 solutions:</p>
  
  <p>1) Modify each project file to create this dist directory tree if it does not already exists.  This seems redundant for me to be required to modify the project file for each new project added to the solution.</p>
  
  <p>2) Created solution .targets files for use with msbuild.exe through the command line.  This worked exactly as I wanted but I prefer a solution that works within visual studio.</p>
  
  <p>If anyone cares, the motivation is to have an easy way to distribute new builds without having to extract the source from them every time. </p>
  
  <p>Update: 5/26/15</p>
  
  <p>I wanted to post my solution here so people with the same issue will have a solution.  I ended up creating an ImportBefore directory in the same directory as my solution file.  In the same directory as the solution there is a directory for each project contained in the solution. This is the standard structure for a visual studio solution and the structure is important as msbuild only has a reference variable for each project.</p>
  
  <p>Place a file with the following content in $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore\ </p>
  
  <p>On my machine it is at C:\Program Files (x86)\MSBuild\12.0\Microsoft.Common.Targets\ImportBefore</p>
  
  <p>My file "importbefore.targets" looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;ImportPath Condition="'$(ImportPath)'==''"&gt;$(MSBuildProjectDirectory)\..\ImportBefore&lt;/ImportPath&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;Import Project="$(ImportPath)\*" Condition="'$(ImportByWildcardBeforeMicrosoftCSharpTargets)' == 'true' and exists('$(ImportPath)')"/&gt;
  
  &lt;/Project&gt;
  </code></pre>
  
  <p>To test that this was working I added the following target file to \ImportBefore or on my computer C:\Users\admin\Dropbox\Projects\BuildTestProject\ImportBefore</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;Target Name="OnlyIfExists" BeforeTargets="Build" Condition="Exists('$(ImportPath)')"&gt;
      &lt;Message Text="Found import directory '$(ImportPath)'" Importance="high" /&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>In the end I will update the project file local to the solution to create a distribution directory only if it is not created and then copy the binaries for the current project that is being built to that distributable directory.</p>