Search code examples
c#model-view-controllerweb-applicationsconsole-applicationpublish

How to run Web Application using console application?


My lecturer gave me task to do in the web application. However, he wants me to send him .exe file because he doesn't have a VisualStudio on his PC. I found on Internet an idea to run web application by console application, becouse console application can be published to .exe file. But have no idea, and didnt find how to do it. Many guides show how to run it on localhost, but they start it from Visual Studio run button, i need .exe file to zip and send to my teacher :/ Its my app here (.NET 6.0, mvc WebApplication). https://github.com/Arachnacein/Mio Its small application just to implement genetics alghorithm for laboratories. It dont have any database and actually I start it by my Visual Studio run button. I did research but didn't find any helpful materials. Thanks for all the help and helpful links.


Solution

  • ASP.NET Core app is a console application. If you want you can use single file deployment which will allow to bundle everything into single file:

    Which also can be done via VS UI by creating reusable publishing profile:

    1. Add <PublishSingleFile>true</PublishSingleFile> to your project file.

    2. On the Solution Explorer pane, right-click on the project you want to publish. Select Publish.

      :::image type="content" source="../media/single-file/visual-studio-solution-explorer.png" alt-text="Screenshot shows Solution Explorer with a context menu highlighting the Publish option.":::

      If you don't already have a publishing profile, follow the instructions to create one and choose the Folder target-type.

    3. Choose Edit.

      enter image description here

    4. In the Profile settings dialog, set the following options:

      • Set Deployment mode to Self-contained or Framework-dependent.
      • Set Target runtime to the platform you want to publish to. Must be something other than Portable.
      • Select Produce single file.

      Choose Save to save the settings and return to the Publish dialog.

      :::image type="content" source="../media/single-file/visual-studio-publish-single-file-properties.png" alt-text="Screenshot shows Profile settings dialog with Deployment mode, Target runtime, and Produce single file options highlighted.":::

    5. Choose Publish to publish your app as a single file.