简体   繁体   English

VS2013 - 如何在使用外部程序的 C# 项目的命令行参数中传递解决方案文件夹 $(SolutionDir)

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

I am building a C# adding for Excel.我正在为 Excel 添加 C#。 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.为了调试它,我需要使用包含插件的调试或发布路径的命令行参数启动 Excel.exe。

For example:例如:

  • Start External Program: C:\\Program Files\\Microsoft Office\\Office15\\EXCEL.EXE启动外部程序:C:\\Program Files\\Microsoft Office\\Office15\\EXCEL.EXE
  • Command line argument "C:\\Dev\\Project1\\Project1\\bin\\Debug\\Project1-AddIn64.xll"命令行参数“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.但是,对于 VS 中的 C++ 项目,我想将“C:\\Dev\\Project1\\Project1\\bin\\Debug”替换为等效的 $(SolutionDir)。 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编辑:请支持我并通过投票支持以下想法将其添加到 VS 中: http : //visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6350738-support-for-macros-in-debugging-命令行参数

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.由于当前文件夹在您启动应用程序时设置为$(TargetDir) ,您可以像这样引用解决方案文件夹: ..\\..\\..\\如果外部程序接受相对路径。 (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).在 Post Build 事件(取消注册)中,以部署组件时应注册的方式注册组件(正确的设置)。 This way you only have to refer to Excel in the Start Action.这样您只需在开始操作中引用 Excel。 This also immediately adds the benefit of testing a scenario that is more similar to production.这也立即增加了测试与生产更相似的场景的好处。

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.如果您从项目模板“Visual C#/. NET Core /Console App”而不是“Visual C#/ Windows /Console App”创建项目,则支持此功能。 When I put "$(SolutionDir)" in the Application Arguments field on the Debug tab of the Project Properties window, it is expanded at run time.当我将“$(SolutionDir)”放在“项目属性”窗口的“调试”选项卡上的“应用程序参数”字段中时,它会在运行时展开。 Note that you will need Visual Studio 2015 Update 3 or later.请注意,您将需要 Visual Studio 2015 Update 3 或更高版本。

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 . @HansPassant 在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像 echo $(ProjectName) > "$(TargetDir)cmdargs.txt

You could substitute cmdargs.txt to appropriate file you want.您可以将cmdargs.txt替换为所需的适当文件。

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.我使用 procmon.exe 来查看 VS 正在寻找什么,实际上我可以使用$(SolutionDir)\\..\\Debug\\thetoolname.exe因为我的解决方案不在根目录中。 Im using VS2019 so AFAIK it is supported from this version but it most likely is supported in lower versions.我使用的是 VS2019,因此 AFAIK 支持此版本,但很可能在较低版本中受支持。 Just use procmon to check the path that VS is attempting to resolve.只需使用 procmon 来检查 VS 试图解析的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 C# 将参数传递给命令行实用程序? - How to pass arguments to command line utility using c#? VS2013的开发人员命令提示符-“”未被识别为内部或外部命令可操作程序或批处理文件 - developer command prompt for VS2013— “ ”is not recognized as an internal or external command operable program or batch file 如何在VS2013中从WinForm生成日志(C#) - How to generate logs from a winform in VS2013(c#) 被只能在VS2013上运行的LightSwitch项目占用时,使用C#7.0调试dll并从VS 2017构建 - Debug a dll using C# 7.0 and build from VS 2017 when consumed by a LightSwitch project that can only run on VS2013 如何使用VS2013在c#中运行可执行文件的进程中调试文件? - How do I debug the file in a process that runs an executable in c# using VS2013? VS2013上C#的VTK包装 - VTK wrap for C# on VS2013 尝试从VS2013 C#程序调用DELPHI XE2 DLL时出错 - Error in trying to call a DELPHI XE2 DLL from VS2013 C# program 如何使用 bash 脚本将命令行 arguments 输入到 do.net c# 程序? - How to input command line arguments to a dotnet c# program using bash scripts? 使用C#和vs 2013的登录命令 - login command using c# and vs 2013 如何使用C#语法将DTEXEC实用工具命令行参数传递给process.start? - How do I pass DTEXEC utility command line arguments to process.start using C# syntax?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM