How to build ASP.NET Core app with Angular on App Runner Code-based service?

1

I have created a ASP.NET Core app with Angular just like the template from Microsoft. The solutions has web API on .NET6 and the Angular 16. I configured app runner build my code using donet6 and build command " dotnet publish -c Release -o out --verbosity normal".

During the App Runner Build, the build command is called twice. The first time it runs perfectly compiling my C# code and Angular JS files using "npm run build -- --configuration=production --progress=true" from the .csproj file.

02-20-2024 01:46:30 PM [Build]        PublishRunWebpack:
02-20-2024 01:46:30 PM [Build]          npm install
02-20-2024 01:46:30 PM [Build]          added 1099 packages, and audited 1100 packages in 17s
02-20-2024 01:46:30 PM [Build]          122 packages are looking for funding
02-20-2024 01:46:30 PM [Build]            run `npm fund` for details
02-20-2024 01:46:30 PM [Build]          found 0 vulnerabilities
02-20-2024 01:46:30 PM [Build]          npm run build -- --configuration=production --progress=true 
02-20-2024 01:46:30 PM [Build]          > app.client@0.0.0 build
02-20-2024 01:46:30 PM [Build]          > ng build --configuration=production --progress=true
02-20-2024 01:46:30 PM [Build]          - Building...
02-20-2024 01:46:30 PM [Build]          Initial Chunk Files   | Names         |  Raw Size | Estimated Transfer Size
02-20-2024 01:46:30 PM [Build]          main.XPW4LF7X.js      | main          | 260.29 kB |                67.41 kB
02-20-2024 01:46:30 PM [Build]          polyfills.T6ZPM373.js | polyfills     |  32.85 kB |                10.68 kB
02-20-2024 01:46:30 PM [Build]          chunk-2XJVAMHT.js     | -             | 449 bytes |               449 bytes
02-20-2024 01:46:30 PM [Build]          styles.YGU7TA3Q.css   | styles        |  25 bytes |                25 bytes
02-20-2024 01:46:30 PM [Build]                                | Initial Total | 293.60 kB |                78.56 kB
02-20-2024 01:46:30 PM [Build]          Application bundle generation complete. [12.338 seconds]
02-20-2024 01:46:30 PM [Build]        _CopyResolvedFilesToPublishPreserveNewest:

However, we the App Runner Build call the build command again, it fails. It does compile all the C# code again. The node.JS does not apear to be working anymore. It says npm command not found.

02-20-2024 01:46:58 PM [Build]        PublishRunWebpack:
02-20-2024 01:46:58 PM [Build]          npm install
02-20-2024 01:46:58 PM [Build]          /tmp/MSBuildTemproot/tmp56c5a0f658624bbf9c9f1723528dd5d2.exec.cmd: line 2: npm: command not found
02-20-2024 01:46:58 PM [Build]          The command "npm install" exited with code 127.
02-20-2024 01:46:58 PM [Build]          npm run build -- --configuration=production --progress=true 
02-20-2024 01:46:58 PM [Build]          /tmp/MSBuildTemproot/tmpf5cb1fdf1fdd40c5b4883f9c1c0bc875.exec.cmd: line 2: npm: command not found
02-20-2024 01:47:04 PM [Build]          The command "npm run build -- --configuration=production --progress=true " exited with code 127.

I can configure my donet project to ignore the npm error, but then only the web api gets published.

	<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" ContinueOnError="true" IgnoreExitCode="true" />
	<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --configuration=production --progress=true " ContinueOnError="true" IgnoreExitCode="true" />

Is there a way to force revised App Runner build for donet6 (which only build one time)? Or is possible to use a post build script to copy the output from the first build? Or is possible to enable Node JS on the second build?

I do not whish to deploy using containers, my goal to build from code with the automatic deployments.

Thank you!

Marco
asked 2 months ago99 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions