title: Visual Studio 2010 build going to wrong folders, creates weird directory called "target"
body: <p>I had a working installation of VS2010 that I used heavily on this machine till about a year ago, and only used infrequently over the last year.  It used to build all my projects just fine, but after having it used last couple of months ago, I opened it up, tried to build a solution, and it fails to build as it seems to create output files in quasi-random places on the hard drive.</p>
  
  <p>To troubleshoot the problem, I simply created a brand new WinForms project, and without changing a single line of code in the template, I built it.  While VS happily declared it built, I see the same problem in it that seems to be plaguing my real solution (which is actually comprised of some 4-5 solutions totaling about 160 projects (C#, some C++) altogether: a directory named "target" is created in the same folder as the .sln file.  Inside that folder is another folder named the same as the solution, and inside of it is bin folder (and further inside are Debug and Release) folders.</p>
  
  <p>Here is the folder structure</p>
  
  <pre><code>C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall.sln
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Release
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug\Test VS after reinstall.exe
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug\Test VS after reinstall.pdb
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\bin
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Form1.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Form1.Designer.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Program.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Test VS after reinstall.csproj
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\bin\Debug
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\bin\Debug\Test VS after reinstall.vshost.exe
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\GenerateResource.read.1.tlog
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\GenerateResource.write.1.tlog
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\TempPE
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\Test VS after reinstall.csproj.FileListAbsolute.txt
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\Test VS after reinstall.exe
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\Test VS after reinstall.pdb
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\obj\x86\Debug\Test_damn_VS_after_reinstall.Properties.Resources.resources
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties\AssemblyInfo.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties\Resources.Designer.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties\Resources.resx
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties\Settings.Designer.cs
  C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\Properties\Settings.settings
  </code></pre>
  
  <p>You can see that 1st and 3rd-8th lines do not seem right.</p>
  
  <p>On my real solution it makes a huge difference because all solutions and projects are configured to build to one common folder, and are all configured by relative paths (output target in build properties).  With all references now screwed up, various projects wind up in various parts of the hard drive, and of course nothing builds properly.</p>
  
  <p>I'm running on Win7SP1 x64, VS2010 Ultimate SP1.</p>
  
  <p>Also worth mentioning that using pre-build steps and echoing some macros (expandable build variables), I can see that macros do not resolve to the right folders.  What's funny is that Visual Studio shows one thing for what it'll be (Project properties, Build Events, pre-build, Edit pre-build, Macros button).  There it shows that the following will be:</p>
  
  <pre><code>Outdir: bin\Debug
  TargetPath: C:\Users\{user}\Documents\Visual Studio 2010\Projects\Test VS after reinstall\Test VS after reinstall\bin\Debug\Test VS after reinstall.exe
  </code></pre>
  
  <p>However, when the build actually runs and pre-build steps are defined as:</p>
  
  <pre><code>echo OutDir: $(OutDir)
  echo TargetPath: $(TargetPath)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>------ Build started: Project: Test VS after reinstall, Configuration: Debug x86 ------
    OutDir: C:\Users\{user}\documents\visual studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug\
    TargetPath: C:\Users\{user}\documents\visual studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug\Test VS after reinstall.exe
    Test VS after reinstall -&gt; C:\Users\{user}\documents\visual studio 2010\Projects\Test VS after reinstall\target\Test VS after reinstall\bin\Debug\Test VS after reinstall.exe
  </code></pre>
  
  <p>Any ideas what's going on with Visual Studio?</p>