admin管理员组

文章数量:1418047

I have a VS 2022 solution that I created from the "Angular and ASP.NET Core" template. The basic folder layout is like this:

-MySln
    -angular.client
    -webapi.server

It runs fine locally.

I have a GitHub .yml workflow to build/deploy them, and it has this line:

run npm run build -- --configuration production --output-path "../webapi.server/wwwroot"

When I look at the final folder structure on the Ubuntu web app (or just download the zip artifact), it looks like this:

~/site
    wwwroot  <- the DLLs are here
        wwwroot   <- nested wwwroot folder
            browser    <- has the index.html etc.

I can get to my swagger page just fine in a browser. But entering just the root gives 404.

If I take out the 'wwwroot' from the yml file, to avoid the nested wwwroots, like this:

run: npm run build -- --configuration production --output-path "../webapi.server"

The .NET Core build will fail that comes right after (maybe because the angular build clears out all the source files in the ASP.NET Core Web API project before output files?)

What am I doing wrong?

I have a VS 2022 solution that I created from the "Angular and ASP.NET Core" template. The basic folder layout is like this:

-MySln
    -angular.client
    -webapi.server

It runs fine locally.

I have a GitHub .yml workflow to build/deploy them, and it has this line:

run npm run build -- --configuration production --output-path "../webapi.server/wwwroot"

When I look at the final folder structure on the Ubuntu web app (or just download the zip artifact), it looks like this:

~/site
    wwwroot  <- the DLLs are here
        wwwroot   <- nested wwwroot folder
            browser    <- has the index.html etc.

I can get to my swagger page just fine in a browser. But entering just the root gives 404.

If I take out the 'wwwroot' from the yml file, to avoid the nested wwwroots, like this:

run: npm run build -- --configuration production --output-path "../webapi.server"

The .NET Core build will fail that comes right after (maybe because the angular build clears out all the source files in the ASP.NET Core Web API project before output files?)

What am I doing wrong?

Share Improve this question edited Feb 3 at 4:57 marc_s 757k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 3 at 4:12 buzzripperbuzzripper 5031 gold badge5 silver badges16 bronze badges 6
  • Please share your Program.cs file. – Harshitha Commented Feb 3 at 4:33
  • Here it is. Thank you so much for looking. pastebin/uvm8CYG6 – buzzripper Commented Feb 3 at 22:22
  • @buzzripper Please share your GitHub workflow file. – Aslesha Kantamsetti Commented Feb 3 at 23:33
  • @buzzripper Are you deploying both the apps to single Azure Web App? – Aslesha Kantamsetti Commented Feb 3 at 23:33
  • Yes, that's what I want to do, have the Web App serve up the angular app, as well as have an API that it will call – buzzripper Commented Feb 4 at 1:26
 |  Show 1 more comment

1 Answer 1

Reset to default 1

I have created sample Angular and Asp.NET core App using Visual Studio template and deployed to Single Azure Web App.

According to this MS Doc when we deploy a combined Angular and ASP.NET Core template to Azure, we only need to publish the ASP.NET application, as it will serve the frontend.

Make sure your .csproj file of the API is like the one below:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <SpaRoot>..\angularapp1.client</SpaRoot>
    <SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
    <SpaProxyServerUrl>https://localhost:60843</SpaProxyServerUrl>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.12" />
    <PackageReference Include="Microsoft.AspNetCore.SpaProxy">
      <Version>8.*-*</Version>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\angularapp1.client\angularapp1.client.esproj">
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
  </ItemGroup>
</Project>

Add below lines to Program.cs file:

app.UseDefaultFiles();
app.UseStaticFiles();
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

Workflow File:

name: Build and deploy ASP.Net Core app to Azure Web App - kaaspangularapp
on:
  push:
    branches:
      - master
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read 
    steps:
      - uses: actions/checkout@v4
      - name: Set up .NET Core
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.x'
      - name: Build with dotnet
        run: dotnet build --configuration Release
      - name: dotnet publish
        run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: -app
          path: ${{env.DOTNET_ROOT}}/myapp
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write 
      contents: read 
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: -app
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_CD22FD0395784F639518925E1EFC70E2 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_66FF58BA62F64705AC9886468C33CB78 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_09510F2585DB4F73936186765AAE5652 }}
      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'kaaspangularapp'
          slot-name: 'Production'
          package: .       

Azure Output:

本文标签: cDeploying AngularASPNET Core Web API to Azure with GitHub ActionsStack Overflow