Home > Net >  VSCode's debug run doesn't seem to honor wwwroot
VSCode's debug run doesn't seem to honor wwwroot

Time:08-11

When working on an ASP.NET 6 project, I attempted to build/run and noticed that none of the wwwroot items were loading. I attempted various things I found online to attempt to fix to no avail.

I then opened the same project in Visual Studio 2019, enabled experimental SDKs (.NET 6 apparently wasn't recognizing without it), and ran it: wwwroot was working as intended. How do I get vscode to treat wwwroot as part of root?

in Program.cs, I have:

 app.UseStaticFiles();

which apparently is required for the process, and each of the style/script tags are some variation of "~/[lib/css/js]/more/path/file.ext"

It works as is when doing a debug run in Visual Studio 2019, but Visual Studio Code 404s all of them.

CodePudding user response:

I had this happen a few months ago, though I don't remember precisely what I did to fix it. I'll try typing out what I think I had done.

I think the problem was with the working directory when running the build, it needed to be in the same directory as where your main DLL is located, and which should also have the wwwroot directory within.

To visualize, your working directory should be set to something like {workspaceRoot}/bin/Debug/net6.0/publish, inside which looks like:

- ...
- YourProject.dll
- wwwroot/

VS Code allows configuring cwd in launch.json, so play with that too.

Edit: Something else that I think helped me out back then: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/?view=aspnetcore-6.0&tabs=windows#content-root

  • Related