首页 > 解决方案 > VSCode won't load static files like css and js when debugging

问题描述

So I recently build a .net core 3.1 web app using Visual Studio on Windows, I then decided to copy the project over to a USB, move it to my Linux machine and keep working on it there.

I managed to run the application but it's not loading the static files such as css, js etc.

It's not a matter of it having the wrong path set in the HTML, I believe it has something to do with my launch.json file

This is my launch.json file, it took some time to generate it, it was having issues to begin such as "Cant locate assets" etc so I changed the "program" node to have the value of where the dll is located and now I can actually debug it and run, but it wont make use of any css files or js etc.

Why is that?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "WARNING01": "*********************************************************************************",
            "WARNING02": "The C# extension was unable to automatically decode projects in the current",
            "WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
            "WARNING04": "been created as a placeholder.",
            "WARNING05": "",
            "WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
            "WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
            "WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
            "WARNING09": "If this allows OmniSharp to now load your project then --",
            "WARNING10": "  * Delete this file",
            "WARNING11": "  * Open the Visual Studio Code command palette (View->Command Palette)",
            "WARNING12": "  * run the command: '.NET: Generate Assets for Build and Debug'.",
            "WARNING13": "",
            "WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
            "WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
            "WARNING16": "button at the bottom of this file.",
            "WARNING17": "*********************************************************************************",
            "preLaunchTask": "build",
            "program": "/home/developer/Desktop/Project/ProjectName/bin/Debug/netcoreapp3.1/ProjecrFile.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Doing this in the bash has seemed to make it use css and what not

dotnet publish -o pubweb


cd pubweb


dotnet projectFile.dll

I'm not sure if that's debugging or if anything is fixed though.

标签: c#asp.netasp.net-corevisual-studio-codeasp.net-core-mvc

解决方案


我刚刚解决了这个问题。

既然你设置

"program": "/home/developer/Desktop/Project/ProjectName/bin/Debug/netcoreapp3.1/ProjecrFile.dll"

你也应该设置

"cwd": "/home/developer/Desktop/Project/ProjectName",

推荐阅读