Project path or other macro in command line options for console project in VS2010

The Debug tab of the project properties for the console application in VS2010 allows me to set command line parameters to go to the project during debugging.

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

For events before and after the build, I can use macros like $(ProjectDir) , but I can’t find a way to do this for command line options - is there a way? Hacking is fine if it's not too terrible!

thanks

+7
source share
2 answers

I have not found a way to use $(ProjectDir) in command line arguments, but you can access the files contained in the project with:

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

This is more of a hack, since it probably does not cover all cases of using this variable, but it can help you if you just refer to several files.

+2
source

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

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

You may have an empty C ++ project “Set as StartUp project” and change it “Configuration Properties → Debugging → Command” from “$ (TargetPath)” (by default for new projects) to “$ (ProjectDir)). \ OtherProjectRelativeDebugFolder \ OtherProjectsOutputFileName.exe ".

Since OtherProjectRelativeDebugFolder and OtherProjectsOutputFileName are relative and therefore location independent, you should be fine with this.

You said:

Hacking is fine if it's not too terrible!

Is an empty project that creates an empty dll (if you don’t find a way to stop it, for example, delete it during post-assembly) is too horrible?

BTW. Environment variables are not allowed in "Debug -> command line arguments" for C #. I will experiment with setting the environment variable by passing its name (because it is not allowed) and reading it in the program. The name transfer is intended to show where the environment variable comes from, i.e. Project parameters.

Edit: I was hoping to find a way to set the environment variable to a macro value, for example. in the build event. The simple "set" command line command is not constant, so it did not work. Instead, I was able to use the relative path as a working folder to make everything work for me. I also found a workaround that uses the file for permanent storage: VS2010 - Project macro variables in the "Startup options" command-line options

+1
source

All Articles