ASP.NET Core Web API json配置未复制到调试文件夹

Har*_*ati 5 c# asp.net configuration json appsettings

我正在研究ASPNET核心Web API应用程序。当我尝试调试应用程序时,“ appsetting.json”文件未复制到调试文件夹。此刻,每当进行更改时,我都将复制此文件。如果我没有复制文件,而只是运行dotnet run命令,则应用程序加载失败,给文件未找到异常。

我应该在Launch.json文件中做什么吗?

这是我的东西。

我也尝试添加

"/appsettings.json":"${workspaceFolder}/appsettings.json"
Run Code Online (Sandbox Code Playgroud)

"sourceFileMap"此JSON文件的属性中,但没有用。

请帮忙。

{
    // Use IntelliSense to find out which attributes exist for C# debugging
    // Use hover for the description of the existing attributes
    // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "attach",
            "name": "Attach to Chrome",
            "port": 9222,
            "webRoot": "${workspaceFolder}"
        },
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/SmartAPI/bin/Debug/netcoreapp2.0/smartAPI.dll",
            "args": [
            ],
            "cwd": "${workspaceFolder}/SmartAPI",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "requireExactSource": false,
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

SBF*_*ies 6

右键单击对象资源管理器中的文件,单击属性并更改“复制到输出目录”的值。创建项目时默认不复制,但可以更改。

更新

没有意识到您正在使用 VS Code - 这个答案可能对您有帮助:/sf/answers/3106488451/