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.
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)
But how to I tell Main to run AutoUpdater?
You can use
Process.Start to run the AutoUpdater exe by providing the path.
Running two projects at once in Visual Studio, Go to Solution properties → Common Properties → Startup Project and select Multiple startup projects. Max has the best solution for when you always want to start both projects, but you can also right click a project and choose menu Debug → Start New Instance. Step 2: Now go to Projects and Solutions -> General section in the tree view on left side of options window and check the checkbox “Always show solution” as shown below That's it now again try to create the project you will be shown by the solution so that you can add as many projects you can.
in your main declare a using.
Then you have easy acces to start the Console.
Running two project at a time in Visual Studio 2019, By default a single project selection is configured as startup project but you can set multiple projects as well. The Solution� Max has the best solution for when you always want to start both projects, but you can also right click a project and choose menu Debug → Start New Instance. This is an option when you only occasionally need to start the second project or when you need to delay the start of the second project (maybe the server needs to get up and running before the client tries to connect, or something).
Use the AutoUpdater project's Post build event to copy the output to a location where the Main application can access.
and/or you can add the AutoUpdater's directory to Path Environment variable and use just the executable name in Process.Start method.
Debug Multiple Projects at the Same Time in Visual Studio , Simply right click the Solution, and select Properties. In the properties window, under Common Properties, select Startup Project. From here we can select the Multiple startup projects option, and then go through and select which projects should launch. A solution needs to have a single entry point It can't start two separate. debuggers on two separate projects, at least within the same editor. If you. opened it in 2 separate editors you could do it, but that would just be. dumb. Usually, when you have multiple projects, you have your main project which.
If you select the Create directory for Solution checkbox, Visual Studio.NET will not place the solution files in the same directory as the project. Instead, it will create a folder for your solution and inside this will create a second folder containing your project.
In Solution Explorer, select the solution (the top node). Choose the solution node's context (right-click) menu and then choose Properties. The Solution Property Pages dialog box appears. Expand the Common Properties node, and choose Startup Project. Choose the Multiple Startup Projects option and set the appropriate actions.
Right click on the solution and select Add then New Project. The dialog field Location defaults to the location of the current project so just leave that field alone. Go through the same steps as for the first project and click the final OK. My example named the second project Second_Project.
- Preferably in a BackgroundWorker ()
- I was hoping that I could do this more dynamically instead of using Process.Start(direct path). @Christian What benefits would it have to use background worker?
- When the projects are compiled, the binaries don't work with projects. So you have to use a path to execute it.
- I don't think there is a need for the BackgroundWorker here, as you don't wait for the process to end, it's a fire and forget type of thing. You may also need to use the ProcessStartInfo class to set more parameters regarding the process' execution
- I'm not here to advocate the BackgroundWorker. However; any process or method call, not executed directly on the UI Thread (which is a very long list btw), should in my book be executed on a separate thread and picked up at convenience. BackGroundWorker made this task very easy. If you wanna fire and forget, dont pickup the response. But why forget? What if the update fails?
- This won't work, an Auto Updater needs to run as a separate process, or else it can't shut down and update the main app without being terminated itself while trying to do so.
- @ilikeclassic That would still be run within the same process and I would run into file lock when trying to overwrite.