Steps to deploy angular 8 along with asp.net core 3.1

Viewed 3901

I have currently created a stand alone Angular 8 Application which is not .net core. I used to deploy it in the IIS and another .net core 3.1 Web Application for WEB API, which is hosted separately and the UI calls the API URL.

Now I have to deploy both together, so I have to merge my Angular 8 application into .net core

Is there a way I could do that instead of going from creating a new .net Core Web Application of type Angular? Is there any best practices for deploying both API and angular application together?

2 Answers

1) create wwwroot in api project if not exists

2) in startup allow app.UseDefaultFiles(); app.UseStaticFiles();

3) prod your angular ng build --prod

4) put you angular dist inside to this wwwroot folder

My steps to deploy an ASP.NET Core Web API 2.2 and Angular 8 application to a hosting provider. Maybe it would be helpful for you.

  1. Create a folder wwwroot into ASP.NET Core Web API project if there is no wwwroot folder
  2. Run ng build --prod in your Angular application.
  3. Copy these build files from the above step into wwwroot folder. You can find your created bundle by seeing "outputPath": "dist/YourAppl", in angular.json file
  4. Publish your ASP.NET Core Web API into folder. Right click at project -> Publish

Put published folder into folder of your website.

This is a web.config in case you want to see detailed errors of your deployed application. It is really helpful to know what should be edited into your deployed application as thrown exceptions can be seen:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="." inheritInChildApplications="false">
    <system.webServer>
        <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" 
                resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".\fooAppl.dll" 
            stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" 
            hostingModel="InProcess" >
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" 
                    value="Development" />
            </environmentVariables>     
         </aspNetCore>
      </system.webServer>
   </location>
</configuration>

In addition, you can read a great article about deploying ASP.NET Core Web API to IIS

Related