Skip to content

Fix static assets when running in non prod mode#2346

Open
GarrettBeatty wants to merge 2 commits intodevfrom
gcbeatty/assets
Open

Fix static assets when running in non prod mode#2346
GarrettBeatty wants to merge 2 commits intodevfrom
gcbeatty/assets

Conversation

@GarrettBeatty
Copy link
Copy Markdown
Collaborator

@GarrettBeatty GarrettBeatty commented Apr 23, 2026

Fix static assets failing to load when ASPNETCORE_ENVIRONMENT is set to non-Production value

Fixes #2118

Description

When ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT is set to anything other than Production (e.g., Development), the Lambda Test Tool's static assets (CSS, JS, BlazorMonaco) fail to load with 404 errors, rendering the web UI completely broken.

Root cause: In TestToolProcess.cs, static file serving was conditional on app.Environment.IsProduction(). In Production mode, an explicit PhysicalFileProvider pointing to AppContext.BaseDirectory/wwwroot was used, correctly serving files from the tool's install directory. In non-Production mode, the bare app.UseStaticFiles() was called instead, which relies on the static web assets manifest (staticwebassets.runtime.json). This manifest contains absolute paths from the build machine (source directories and NuGet cache paths) that don't exist on end-user machines, causing all static asset requests to return 404.

Fix: Always use the explicit PhysicalFileProvider to serve static files from the tool's install directory (AppContext.BaseDirectory/wwwroot), regardless of the environment. UseDeveloperExceptionPage() is still conditionally applied for non-Production environments.

Testing

Setup:

cd Tools\LambdaTestTool-v2\src\Amazon.Lambda.TestTool
dotnet pack -c Release
dotnet tool uninstall -g amazon.lambda.testtool
dotnet tool install -g amazon.lambda.testtool --version 0.13.0 --add-source bin\Release

Before fix — reproduce the bug:

cd C:\Users\<user>\Desktop  # navigate away from the repo source directory
$env:ASPNETCORE_ENVIRONMENT = 'Development'
dotnet-lambda-test-tool start --lambda-emulator-port 5099 --no-launch-window

From a second terminal:

(Invoke-WebRequest -Uri 'http://localhost:5099/app.css').StatusCode
# Returns 404 ❌

After fix — verify the fix:

# Re-pack and re-install with the fix applied, then:
cd C:\Users\<user>\Desktop
$env:ASPNETCORE_ENVIRONMENT = 'Development'
dotnet-lambda-test-tool start --lambda-emulator-port 5099 --no-launch-window

From a second terminal:

(Invoke-WebRequest -Uri 'http://localhost:5099/app.css').StatusCode
# Returns 200 ✅

Baseline — confirm no regression in Production mode:

$env:ASPNETCORE_ENVIRONMENT = $null
dotnet-lambda-test-tool start --lambda-emulator-port 5099 --no-launch-window
(Invoke-WebRequest -Uri 'http://localhost:5099/app.css').StatusCode
# Returns 200 ✅

@GarrettBeatty GarrettBeatty requested a review from a team as a code owner April 23, 2026 15:19
@GarrettBeatty GarrettBeatty changed the base branch from master to dev April 23, 2026 15:19
@GarrettBeatty GarrettBeatty marked this pull request as draft April 23, 2026 15:37
@GarrettBeatty GarrettBeatty marked this pull request as draft April 23, 2026 15:37


<!-- Ensure wwwroot content is copied to output directory -->
<ItemGroup>
Copy link
Copy Markdown
Collaborator Author

@GarrettBeatty GarrettBeatty Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unit tests need this to pass. my guess is dotnet build does not auto copy the wwroot to the output directory.

However when i did the manual testing (as in the pr description), it seems like dotnet pack auto copy everything which is why this change wasn't needed then. But when i ran the tests i had to add in b559dd5

@GarrettBeatty GarrettBeatty marked this pull request as ready for review April 23, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants