How can I redirect the "bin" and "obj" directories to a different location?

Refer to this article and use the nodes BaseOutputPath (for the bin folder) and BaseIntermediateOutputPath (for the obj folder) in the .proj file.

Given below is a way to modify your debug and release folders relative to bin -

In Solution Explorer, select the C# project you want to configure build parameters on.

Next, from the Visual Studio menu bar, select ProjectProperties. The Property Pages dialog will appear for your project.

Choose the Configuration (Release/Debug) you want to change and expand the Configuration Properties node in the left hand pane. Select the Studio is placed in the "Output path" attribute of the Outputs property sheet.

Be aware that the output path is specified separately for each kind of build configuration, and that setting it on one configuration doesn't set it on all the remaining ones.

Original source - http://www.eggheadcafe.com/software/aspnet/32040244/how-to-change-the-obj-folder.aspx


To move obj directories out of your code base to another common folder you can do the following. Create Directory.Build.props in the root directory of your solution with the following content:

<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>$(SolutionDir)\_Obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

To keep folder structure in your common obj directory the same as in your solution you can create files with the same and similar content in every subfolder of your solution. E.g. If you have subfolder Algorithms which contains several projects you can put file with the following content into it:

<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>$(SolutionDir)\_Obj\Algorithms\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

Use BaseOutputPath for bin folder.

  • More info on Directory.Build.props
  • More info on MSBuild macroses