Select correct Angular Environment based on .Net Core build

后端 未结 2 1135
夕颜
夕颜 2021-02-08 04:59

I created an .Net Core Web Api with an Angular ClientApp with the templates from Visual Studio.

When building the project also builds the contained Angular App with the

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 06:00

    I kind of found a solution by manipulating the *.csproj after all.

    HINT: To be clear this problem only applies when you created your project with the Visual Studio .Net Core Web Api with Angular Template which creates a combined web api with clientapp project

    After I found out that I could add custom Build Configurations for dotnet build I added the following lines to the block:

    
    
    

    and in package.json add to scripts:

    "scripts": {
            "build-staging": "ng build --configuration=staging",
            "build-prod": "ng build --configuration=production",
        },
    

    What it does, is on different build configs set by the Condition attribute, npm run build is called with a corresponding/appropriate environment.

    Another, perhaps more easy approach, would be to have two build pipelines, one for npm and the angular app and one for the dotnet web api. While doing so, you may want to remove the whole build SPA stuff from the *.csproj otherwise it will build the app twice.

    Or just have 2 separate projects in the first place and spare yourself the hassle :)

    EDIT:

    As pointed out Command="npm run build --configuration=production" (e.g. build with mutliple params) is not picked up by the CI/CD. So using predefined scripts from package.json is the correct way to go :)

提交回复
热议问题