VS2013 - How to pass a solution folder, $ (SolutionDir), to command line arguments for a C # project using an external program

I am creating a C # add-on for Excel. To debug it, I need to run Excel.exe with a command line argument containing the Debug or Release path to addin.

For example:

  • Launch an external program: C: \ Program Files \ Microsoft Office \ Office15 \ EXCEL.EXE
  • The command line argument is "C: \ Dev \ Project1 \ Project1 \ bin \ Debug \ Project1-AddIn64.xll"

However, I would like to replace "C: \ Dev \ Project1 \ Project1 \ bin \ Debug" with the equivalent of $ (SolutionDir) for C ++ projects in VS. Is there any way to do this? If this is not feasible, is there a way around this?

EDIT: please support me and add to VS by voting the following idea: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6350738-support-for-macros-in-debugging-command-line -argum

+5
source share
3 answers

Indeed, macros cannot be used in startup parameters | Command line arguments

I see two solutions:

  • When the current folder is set to $(TargetDir) when the application starts, you can access the folder with the solution as follows: ..\..\..\ if the external program takes a relative path. (I'm not quite sure why you will ever want to access the solution folder, referring to the output / target folder, makes more sense to me)

  • In the Post Build event (unregister) and register the component as the component should be registered during its deployment (correct configuration). Thus, you will only need to reference Excel in the Start action. It also immediately adds the benefit of script testing, which is more like production.

+5
source

I think you could use the post-build event to read in your file. @HansPassant explained this in VS2010 - project macro variables in the command line options of the launch options .

Short quote:

A possible workaround is the post-build event, which writes the file that you are reading in your program. How echo $ (ProjectName)> "$ (TargetDir) cmdargs.txt

You can replace cmdargs.txt with the desired file.

+1
source

This is not quite a fix, but it may help some people. If you create your project from the project template "Visual C # / .NET Core / Console Application" instead of "Visual C # / Windows / Console Application", this function is supported when I put "$ (SolutionDir)" in the "Application Arguments" field "on the Debug tab of the Project Properties window, it expands at run time. Please note that you will need to update Visual Studio 2015 Update 3 or later.

0
source

All Articles