使 MSBuild 的 Exec 任务显示交互式 shell

发布于 2024-11-15 08:27:44 字数 685 浏览 0 评论 0原文

以下两段是背景 - 它们只是解释为什么我需要做这么奇怪的事情。如果您不在乎,可以跳过它们并直接进入问题。
我是 Vim 用户,我开始学习 C#。当然,我想使用 MSBuild 作为我的 makeprg。我想为常见的开发操作绑定热键 - BuildCleanRun。由于我想在全局范围内设置热键,因此我遇到了一个问题,因为每个项目中的文件名都不同。

在 GCC/MinGW 中,这个问题可以很容易地解决 - 因为我已经将重要的文件名存储在变量中,所以我可以简单地添加到 makefile 目标中以清理构建并运行程序,然后将热键绑定到“:make!清洁”和“:运行!”所以我想我可以用 MSBuild 目标做同样的事情。它对于带有删除标记的Clean非常有用(不确定我是否真的需要.NET中的clean,但你知道 - 习惯的力量),但我对Run有问题。

现在,这是我的问题:与 GCC/MinGW 的 makefile(只是运行 shell 命令的巧妙批处理文件)不同,MSBuild 使用它自己的命令集并在内部运行它们。这意味着 Exec 任务在没有 shell 的情况下运行程序 - 我可以打开窗口,但无法使用它来测试交互式 shell 程序。

有什么方法可以说服 MSBuild 给我一个交互式 shell 吗?

The following two paragraphs are background - they just explain why I need to do such a weird thing. If you don't care you can skip them and go directly to the question.
I'm a Vim user and I started learning C#. Naturally I want to use MSBuild as my makeprg. I want to bind hotkeys for common development operations - Build, Clean and Run. Since I want to set my hotkeys globally, I have a problem as the files' names are different in each and every project.

In GCC/MinGW this problem could be solved easily - since I'm already storing the important file names in variables, I can simply add to the makefile targets for cleaning the build and running the program, and then bind hotkeys to ":make! Clean" and ":make! Run". So I figured I could do the same thing with MSBuild targets. It works great for Clean with the Delete tag(not sure I really need clean in .NET, but you know - force of habit), but I have a problem with Run.

Now, this is my problem: unlike GCC/MinGW's makefiles, which are simply clever batch files that run shell commands, MSBuild uses it's own set of commands and runs them internally. That means that Exec tasks run the program without a shell - I can open windows, but I can't use it to test interactive shell programs.

Is there any way to persuade MSBuild to give me an interactive shell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2024-11-22 08:27:44

您是否尝试过这种方法的一些变体,

<Exec Command="start $(COMSPEC) /k "$(PathTo)\My.exe & exit"" />

在转义之后,结果大致如下,

C:\Windows\system32\cmd.exe /k "PathTo\My.exe & exit"

它将在命令 shell 中运行您的命令(/k 可能不是适合您使用的正确的 cmd 开关),然后当您的交互式程序退出时,它将运行“退出”命令并继续。


Have you tried some variation of this,

<Exec Command="start $(COMSPEC) /k "$(PathTo)\My.exe & exit"" />

After escaping it works out to roughly this,

C:\Windows\system32\cmd.exe /k "PathTo\My.exe & exit"

Which will run your command within a command shell (/k may not be the right cmd switch for your usage), then when your interactive program exits, it will run the "exit" command and move on.


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文