In VS 2008, is there a way to set the intermediate directory (where the .obj files go, not the final targets) in a C# project?
Right-click on the project node in Solution Explorer and select Properties. Expand the Build section, and select the Output subsection. Find the Base output path for C#, and type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that folder instead.
In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.
Open project properties. Set Output type to Console Application. Save and close.
You need to override BaseIntermediateOutputPath msbuild var, more about it here.
I found a solution to this using Visual Studio Express 2013; I forget which version of VS introduced MSBuild, and I can't say for sure that this will work for any other version. But here goes:
In C:\Windows\Microsoft.NET\Framework
are subdirectories corresponding to .NET versions; With VSX2013 on my system the folder of interest is v4.0.30319
. (That's the .NET version used by MSBuild, not the one I'm targeting.) Within this folder are .targets
files, which are collections of MSBuild rules.
Near the beginning of Microsoft.CSharp.targets
are some rules that will import more rules files. The third of these import statements imports from the file named by the build variable CustomBeforeMicrosoftCSharpTargets
. You might be able to figure out the name of this by reading the rules, but it's easier to add a custom build step of
echo $(CustomBeforeMicrosoftCSharpTargets)
Build and look at the output. In my case, the full path was
C:\Program Files (x86)\MSBuild\v12.0\Custom.Before.Microsoft.CSharp.targets
NOTE: in my case, there was already a folder C:\Program Files (x86)\MSBuild\12.0
but not v12.0
.
So (as admin) I created the folder and placed a Custom.Before.Microsoft.CSharp.targets
file that looks like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BaseIntermediateOutputPath>$(SolutionDir)\Build\$(MSBuildProjectName)</BaseIntermediateOutputPath>
</PropertyGroup>
</Project>
NOTE: $(ProjectName)
does not work, use $(MSBuildProjectName)
.
When I built, the OBJs were placed under a Build directory under the solution, not under the project, in a subdirectory with the typical naming convention: Debug
or Release
or x86\Debug
or x64\Release
.
This did not work exactly as desired: I really wanted to place these in %TEMP%
but the variable was not expanded, so I ended up with a build folder under the project called %TEMP%
. Placing the expanded path in the rule worked just fine, but other subfolders of %APPDATA%
failed due to permissions issues.
I assume this can be used to configure any of those variables; reading the default .TARGETS
files is a chore but there are some useful comments therein.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With