Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 542
user380719 Avatar asked Jan 19 '11 13:01

user380719


People also ask

What is the difference between OBJ and bin folders?

The obj directory is for intermediate object files and other transient data files that are generated by the compiler or build system during a build. The bin directory is the directory that final output binaries (and any dependencies or other deployable files) will be written to.

Can I delete obj and bin folders?

Delete bin and obj foldersThe bin and obj folders are usually safe to delete since they are automatically generated when the solution/project is being build by Visual Studio/MSBuild. This feature is off by default, but can easily be enabled in the settings.

What is a OBJ folder?

"obj" folder is used to store temporary object files and other files used to create the final binary.


2 Answers

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

like image 119
Sachin Shanbhag Avatar answered Oct 29 '22 11:10

Sachin Shanbhag


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
like image 28
Yola Avatar answered Oct 29 '22 10:10

Yola