10

The debug tab of the project properties for a console application in VS2010 allows me to set command-line parameters to pass to the project whilst debugging.

I would like to set a parameter which is a path and the path is specific to each developer/machine, as it is a path which resides in the solution folder and each environment is different.

For pre- and post-build events, I can use macros such as $(ProjectDir), but I can't find a way to do this for command-line parameters - is there a way? A hack is fine, as long as it's not too awful!

Thanks

2 Answers 2

2

I haven't found a way to use $(ProjectDir) in the command line arguments, but you can access files contained within the project by:

  • Tell Visual Studio to copy specific files to the output directory by changing their "Copy to Output Directory" property.
  • Change your command line arguments from $(ProjectDir)/FileNeededDuringRuntime to FileNeededDuringRuntime.

This is more of a hack since it probably doesn't cover all the cases of using the variable, but it may get you by if you're just referencing a few files.

1

Macros can be used in command line arguments for C++ projects, see:

How to pass solution folder as parameter in command line arguments (for debug)?

You could have an empty C++ project "Set as StartUp Project" and change its "Configuration Properties -> Debugging -> Command" from "$(TargetPath)" (default for new projects) to "$(ProjectDir)..\OtherProjectRelativeDebugFolder\OtherProjectsOutputFileName.exe".

Since OtherProjectRelativeDebugFolder and OtherProjectsOutputFileName are relative and thus location independent you should be fine with that.

You said:

A hack is fine, as long as it's not too awful!

Is an empty project that produces an empty dll (unless you find a way to stop it, e.g. delete on post-build) too awful?

BTW. Environment variables aren't resolved in "Debug -> command line arguments" for C# either. I'll be experimenting on setting an environment variable, passing its name (because it isn't resolved) and reading it in the program. Passing the name is intended to show where the environment variable comes from, i.e. project settings.

Edit: I hoped to find a way to set the environment variable to the value of a macro, e.g. in a build event. A simple shell "set" command is not persistent, so it didn't work out. Instead I was able to use a relative path as working folder to get things work for me. I also found a workaround that uses a file for persistent storage: VS2010 - Project Macro Variables in Start Options Command Line Arguments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.