How do I start a background task from a VisualStudio post-build event?

前端 未结 1 1846
情深已故
情深已故 2021-02-06 11:50

I\'m trying to start an instance of grunt watch whenever a particular project is run from VisualStudio. I have a single page-app written in ember, and compiled with grunt, whic

1条回答
  •  无人及你
    2021-02-06 12:13

    Not sure why exactly start doesn't do the trick (works perfectly from the command line), but afaik msbuild spawns a seperate cmd process for it's build events so it will have something to do with that.

    A working alternative is to use Powershell to start the process instead. No idea about the builtin powershell syntax, but invoking C#'s Process.Start works just as fine:

    powershell -Command "[System.Diagnostics.Process]::Start( '/path/to/node', 'args' )"
    

    That answers your question, however I think it's not what you really want, and you're asking the wrong question.. You say you want to 'start an instance whenever a particular project is run from VisualStudio', but then you go on asking about build events which occur when a project is built. That is different and seems unhandy since every single build will start a new instance. Instead, I think what you actually want/need is to start an instance everytime you start debugging your project. That's also possible as laid out here:

    • add an empty project to your solution
    • enter your node command under the projects' Properties->Debugging
    • right-click solution, select Set Startup Project
    • select Multiple startup projects
    • set Action to Start for your main project
    • set Action to Start without debugging for the empty project

    Now hit F5 and VS will start node, plus start debugging your project.

    0 讨论(0)
提交回复
热议问题