user380719
user380719

Reputation: 9903

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

Is there a way to tell Visual Studio to use a different location for the bin and obj directories?

For example, if my project is in C:\my\myprojects.csproj, how can I have the obj and bin directories in, say, D:\otherdirectory\bin and D:\otherdirectory\obj. The Visual Studio project option offer only to redirect the bin directory, not the obj directory.

Also, bonus question: Can I use environment variables, not full or relative paths?

Is this possible?

Upvotes: 28

Views: 23198

Answers (4)

pixelgrease
pixelgrease

Reputation: 2118

In Visual Studio 2013, this is specified in project "Configuration Properties/General/Intermediate Directory". enter image description here

Upvotes: 0

Yola
Yola

Reputation: 19033

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.

Upvotes: 17

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

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

Upvotes: 22

Koen
Koen

Reputation: 2571

In the Project-options in the tab Build you can choose the output path (in the bottom-section).

Upvotes: 0

Related Questions