[英]Run a second project from within the same solution
I've been tasked with building a custom updater but are struggling with how to run this.我的任务是构建自定义更新程序,但正在努力解决如何运行它。 I could of course just create a separate app to take care of this but it is preferred that it all stay in the same solution.
我当然可以创建一个单独的应用程序来处理这个问题,但最好都保留在同一个解决方案中。 In my solution I have the project "Main" which is a Forms application and the project "AutoUpdater" which is a console application.
在我的解决方案中,我有一个表单应用程序项目“Main”和一个控制台应用程序项目“AutoUpdater”。
My idea was to have "Main" run the "AutoUpdater" console app in a separate process or possibly have the program copy the autoupdater.exe in a temp folder and then run it from there (to prevent file lock)我的想法是让“Main”在单独的进程中运行“AutoUpdater”控制台应用程序,或者可能让程序将 autoupdater.exe 复制到临时文件夹中,然后从那里运行它(以防止文件锁定)
But how to I tell Main to run AutoUpdater?但是如何告诉 Main 运行 AutoUpdater?
您可以使用Process.Start
通过提供路径来运行 AutoUpdater exe。
in your main declare a using.在您的主要声明中使用。
using AutoUpdater;
Then you have easy acces to start the Console.然后,您可以轻松访问控制台。
Use the AutoUpdater project's Post build event to copy the output to a location where the Main application can access.使用 AutoUpdater 项目的 Post build 事件将输出复制到主应用程序可以访问的位置。
Read more here : https://docs.microsoft.com/en-us/visualstudio/ide/how-to-specify-build-events-csharp?view=vs-2019在此处阅读更多信息: https : //docs.microsoft.com/en-us/visualstudio/ide/how-to-specify-build-events-csharp?view=vs-2019
and/or you can add the AutoUpdater's directory to Path Environment variable and use just the executable name in Process.Start method.和/或您可以将 AutoUpdater 的目录添加到 Path Environment 变量,并在 Process.Start 方法中仅使用可执行文件名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.