Launching a project from another

115 views Asked by At

I am attempting to provide a WPF application to a user that can be run locally.

I currently have a WebAPI project that serves as an API for modifying data in a database as normal. This is fully working as intended.

I have a class library that I have written some internal classes that are necessary for the running of a WPF project I will be providing to users- with this class package referenced.

I wanted to create this class library so that the WPF project they are given has minimal editable code that they could potentially change and break the application. This is all fine and set up.

The WPF project I have created provides a user interface for users to view and modify data in a local database (provided with the project). The purpose of providing this project to the user is so that they may modify or create new classes within the project that can be used to extend our solution.

I have the local DB, WPF project and class library all set up and working as intended, however, I would like to include the WebAPI project so that when they run the WPF application locally, an instance of the WebAPI is also run locally in the background- on a .NET local webserver as if I had press run in the WebAPI project.

The issue with this however, is I would rather not just give them the entire WebAPI project to load and run themselves within the WPF solution, and would like an instance of the WebAPI to just begin when the WPF application begins, so that they may either manipulate the database data via the WPF interface, or via sending requests from another source to the locally running API.

Is it possible to launch an instance of the WebAPI (as if I pressed F5 in the WebAPI project) when the WPF application starts without including the WebAPI project in the WPF solution?

I would like to simply include a DLL of the WebApi in the WPF project and launch an instance of it in a local .NET webserver when the WPF application starts. Is this possible? Can you launch a built DLL into a local webserver from another standalone project that references or includes said DLL?

I have looking into Cassini and some other options, such as converting it to an EXE but I think they are much more complicated than what I need and I don't want to start retrofitting code should there be an easier way I have not stumbled across online yet.

2

There are 2 answers

0
edita On

You could provide them with the published WebAPI files and have them setup an instance in their local IIS, then have the WPF project reference that local instance. This may be feasible only if the volume of users is relative low, however.

0
Ben Maxfield On

For anyone else who would like to know how to do this, using editas idea, I placed the published files into a folder that would be included with the package given to the user and on WPF application start called into the class library referenced to initialise the API using a method I wrote: InitialiseAPI().

This method works by calling an EXE that silently launches an instance of IIS Express on the users machine attaching the 'published' files to the instance. This works perfectly, I also created and application exit method to destroy the IIS instance on exit, so when they restart the application it doesn't throw a port in use exception.