Artium
Artium

Reputation: 5331

How to Store Visual Studio's Debug Configuration in Source Control

Visual Studio's debug configurations are stored in the .user file which is user specific and traditionally ignored by source control.

I am interested in the working directory parameter. I need it to be consistent across programmer's machines and it have the value of $outDir instead of the default $ProjectDir.

How can I resolve these contradictions?

Upvotes: 7

Views: 1596

Answers (2)

zeromus
zeromus

Reputation: 1667

Add this to the end of the vcxproj before the </project> tag:

  <PropertyGroup>
    <LocalDebuggerWorkingDirectory>c:\same\for\everyone</LocalDebuggerWorkingDirectory>
  </PropertyGroup>

I just checked it on 2010.

Visual studio will still show $(ProjectDir) in the IDE because I guess it populates it with whatever it finds in the .user file, but during building tasks it seems to process the .user file after the vcxproj; without an override in the .user it seems to accept what's set in the vcxproj.

Note that if you put this at the end of the vcxproj as I suggested, it is necessarily after the import of Microsoft.Cpp.props which is all that's important as @Claytorpedo points out

Upvotes: 13

Claytorpedo
Claytorpedo

Reputation: 179

Adding to @zeromus's answer by request.

You can set the working directory in the vcxproj like so:

<PropertyGroup>
  <LocalDebuggerWorkingDirectory>c:\same\for\everyone</LocalDebuggerWorkingDirectory>
</PropertyGroup>

However, for it to work, it needs to be defined after

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

If you define LocalDebuggerWorkingDirectory before that import, it will be overridden back to the default location.

You can also use relative paths. For instance in one project, I have it set like:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
  <LocalDebuggerWorkingDirectory>..</LocalDebuggerWorkingDirectory>
</PropertyGroup>

so that it starts from one directory above the vcxproj file.

Tested in VS 2019.

Upvotes: 6

Related Questions