Search code examples
docker.net-corenugetcontainers

Blazor .Net app in Docker Container getting public NuGet dlls but not js or css files


I am running into an issue where I am deploying a Blazor app that contains several public NuGet packages into a Linux Docker container. The container builds properly and adds the appropriate dll files of the packages into /app and /scr, but it isn't putting the js files into the wwwroot folder.

I can reproduce this with a minimal app by:

  • starting a new Blazor app with Docker support,
  • adding a public NuGet package (in this case, BlazorInputMask)
  • adding the calls to _Layout.cshtml for the js files
    •    <script type="text/javascript" src="_content/BlazorInputMask/Main.js"></script>
         <script type="text/javascript" src="_content/BlazorInputMask/IMask.js"></script> 
      
  • Running the app locally using the Docker debugger
  • Checking the Network calls in the browser and seeing a 404 - Main.js not found
  • Checking the files in VS's Docker tools, and navigating to wwwroot, where Main.js and IMask.js are not found.

This works properly when doing a non-containerized build. It's just the container that is the problem.

The problem exists with the scaffolded Dockerfile generated by VS.

I tried laying out a Nuget.config file with the following code, but I got the same behavior:

<packageSources>
  <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  <add key="wcmMapsSrc" value="." />
</packageSources>

Solution

  • Well, I found the problem!

    There is a case mismatch between the NuGet package's docs and code base. In the docs, they reference Main.js but the filename is main.js.

    This never presented a problem in any non-Dockerized deployment we have run, all of which have been Windows-based. However, when run through the Linux container there must be some case-sensitivity added.

    Updating my codebase to reference the proper script file name solved the issue.

    <script type="text/javascript" src="_content/BlazorInputMask/main.js"></script>

    Turns out, not a NuGet concern. Leaving this here for others.