I have a C++ solution in VS2008 with multiple projects. This solution contains files that are needed at runtime, which are loaded according to a path relative to the solution directory (e.g. "Testing/data/" + "dataN.bin"
).
In order for this solution to work, I must set the working directory setting in the project(s) so that it will point to the solution directory (e.g. Configuration Properties >> Debugging >> Working Directory = $(SolutionDir)
). This works fine when i'm debugging on my own PC. However, when a different user loads my solution, his projects does not have this property set properly.
I have traced this setting to be stored not in the project file (PROJECT.vcproj
), but in the user-specific file created for it (PROJECT.vcproj.DOMAIN.USER.user
).
I would like a way for this setting to be stored for ALL users, without having to set it manually again and again.
My thoughts were:
However, I did not find a way to do either of these.
A few more notes / constraints:
Any help will be appreciated... thanks in advance.
Sample PROJECT.vcproj.user file is provided below
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9,00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(ProjectDir)..\Deploy\$(ConfigurationName)\$(TargetFileName)"
WorkingDirectory="$(ProjectDir)..\Deploy\$(ConfigurationName)\"
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="LOCALHOST"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(ProjectDir)..\Deploy\$(ConfigurationName)\$(TargetFileName)"
WorkingDirectory="$(ProjectDir)..\Deploy\$(ConfigurationName)\"
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="LOCALHOST"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>
No such property exists. There are bigger issues, this also needs to work after you deploy your solution. The working directory then is not going to be a "solution" directory, there isn't one on the target machine.
You are much better off working from the assumption that the working directory is the same as the EXE directory. That will be the default both while debugging and on the target machine. You have full control over the location of the EXE file with a linker setting. And you can protect yourself from a shortcut running your program with another working directory by obtaining the EXE directory in your code so you can generate an absolute path. Use GetModuleFileName(), pass NULL to get the path to the EXE file.
Another standard solution is to copy any kind of resources the EXE needs to a folder that's relative from the build output folder. You do this with a Pre-Build event, make the command line look similar to this:
if not exist "$(OutDir)\Testing" md "$(OutDir)\Testing"
xcopy /d /s "$(SolutionDir)\Testing\*.*" "$(OutDir)\Testing
Note how the /d option ensures that copying is only done if the Testing folder content changed.
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