How to configure the intermediate output directory in C#

Viewed 32164

I'm trying to organize my workspace and want my intermediate objects to be put in the ..\build\obj folder in relation to my .csproj file. So I put:

<IntermediateOutputPath>..\build\obj\Debug</IntermediateOutputPath>

in the .csproj file. The intermediate objects are now put in that location when the solution is built, but the problem is that an obj directory is still created in the directory the .csproj file is in (something to the effect of obj\Debug\TempPE) when the solution is opened. What is this directory for, and how can I relocate it?

4 Answers

According to this post, a file named Directory.Build.props can be created in the folder that containes the .csproj project file. In order to relocate the obj folder, we can add

<BaseOutputPath>..\Build</BaseOutputPath>

to the PropertyGroup section in .csproj project file, and write

<?xml version="1.0"?>
<Project>
    <PropertyGroup>
        <BaseIntermediateOutputPath>..\Intermediate\obj</BaseIntermediateOutputPath>
        <IntermediateOutputPath>$(BaseIntermediateOutputPath)\$(Configuration)</IntermediateOutputPath>
        <!--The following is the default configuration for "MSBuildProjectExtensionsPath"-->
        <!--<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath>-->
    </PropertyGroup>
</Project>

to the Directory.Build.props file.

I've used:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>$(OBJDIR)\$(SolutionName)\bin\$(Configuration)\</OutputPath>
    <BaseIntermediateOutputPath>$(OBJDIR)\$(SolutionName)\obj\$(Configuration)\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)\</IntermediateOutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
</PropertyGroup>

(In Visual Studio 2012 Beta, FWIW), and it works fine.

The OBJDIR on my machine points to E:\BuildOutput.

Related