7

I am building a C# adding for Excel. In order to debug it, I need to launch Excel.exe with a command line argument containing the Debug or Release path to the addin.

For example:

  • Start External Program: C:\Program Files\Microsoft Office\Office15\EXCEL.EXE
  • Command line argument "C:\Dev\Project1\Project1\bin\Debug\Project1-AddIn64.xll"

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

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

BlueTrin
  • 9,610
  • 12
  • 49
  • 78
  • 2
    I believe those macros are only available within Visual Studio and msbuild. If you are locally debugging it, it may be faster to make a quick .bat file with hard-coded values. – gunr2171 Aug 25 '14 at 18:53

4 Answers4

6

Indeed, the macros cannot be used in the Start Options | Command line arguments

I see two solutions:

  1. As the current folder is set to the $(TargetDir) when you Start an application you could refer to the solution folder like this: ..\..\..\ if the External program accepts a relative path. (I am not quite sure why you would ever want to refer to the solution folder, referring to the output/target folder makes more sense to me)

  2. In the Post Build event (unregister) and register the component the way the component should be registered when deploying it (a proper setup). This way you only have to refer to Excel in the Start Action. This also immediately adds the benefit of testing a scenario that is more similar to production.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • Did you try this with a C# program ? My problem is that these macros do not seem to be recognised in the C# command line arguments for some reason. – BlueTrin Aug 25 '14 at 20:40
  • 1
    I'll give it a go and will report within 24 hrs unless someone beats me to it. I've done this before but perhaps it were different circumstances. – Emond Aug 25 '14 at 20:51
2

It's not exactly a fix, but this may help some people. If you create your project from the project template "Visual C#/.NET Core/Console App" instead of "Visual C#/Windows/Console App", this feature is supported. When I put "$(SolutionDir)" in the Application Arguments field on the Debug tab of the Project Properties window, it is expanded at run time. Note that you will need Visual Studio 2015 Update 3 or later.

Gyromite
  • 769
  • 6
  • 16
1

I guess you could make use of post-build event to read in your file. @HansPassant explained it in VS2010 - Project Macro Variables in Start Options Command Line Arguments.

A short quote:

A possible workaround is a post-build event that writes a file that you read in your program. Like echo $(ProjectName) > "$(TargetDir)cmdargs.txt

You could substitute cmdargs.txt to appropriate file you want.

Community
  • 1
  • 1
nevets
  • 4,631
  • 24
  • 40
  • 1
    In this case I need to debug Excel, so I cannot make Excel read this txt file. Also for some reason, if you redirect the command line in a .bat, the .bat cannot be fed as command line to launch for Visual Studio. – BlueTrin Aug 25 '14 at 21:10
0

You CAN use the macros in the Command fields. I used procmon.exe to see what VS was looking for and indeed i could use $(SolutionDir)\..\Debug\thetoolname.exe as my solution was not in the root. Im using VS2019 so AFAIK it is supported from this version but it most likely is supported in lower versions. Just use procmon to check the path that VS is attempting to resolve.

Justin
  • 3,255
  • 3
  • 22
  • 20