How to start Angular frontend with C# backend

Discussão em 'Angular' iniciado por Paba, Fevereiro 21, 2025.

  1. Paba

    Paba Guest

    I have created a C# WinForms program with a WebView2 control to show an Angular user interface. The Angular frontend was created in Visual Studio Code and so far I used npm to serve the Angular frontend for development. But in the end the target is that my C# backend can start the Angular frontend by itself to show the user interface.

    I already managed to do this by the following code, which simply starts the npm service in the background to make the frontend accessible for the WebView2 control:

    string angularProjectPath = @"C:\workspace\software\mcinspect_cs\sources\Client\mcinspect\src";

    // Set the command to start the Angular development server
    string command = "npm start";

    // Start the Angular development server process
    ProcessStartInfo psi = new ProcessStartInfo
    {
    FileName = "cmd.exe",
    RedirectStandardInput = true,
    UseShellExecute = false,
    WorkingDirectory = angularProjectPath,
    CreateNoWindow = true
    };

    g_uiProcess = Process.Start(psi);
    g_uiProcess.StandardInput.WriteLine(command);


    But with this approach, the user of my program needs to have npm installed on his computer to use the software. I was wondering if there is an alternative way to provide a webserver by my C# project to serve the user interface. I saw there are some Angular Nugets available, but I'm not sure if I can use one of these to do this. I would prefer a solution where the serve of my frontend is fully integrated into my C# project to show the user interface. What is the right way to do it?

    I used the code in the description to serve my frontend.

    Continue reading...

Compartilhe esta Página