【问题标题】:ASP.NET core web API json configuration not copied to debug folderASP.NET 核心 Web API json 配置未复制到调试文件夹
【发布时间】:2018-01-21 23:17:13
【问题描述】:

我正在开发一个 ASPNET 核心 Web API 应用程序。当我尝试调试应用程序时,“appsetting.json”文件不会复制到调试文件夹中。此刻,每当我进行更改时,我都会复制此文件。如果我没有复制文件而只是运行dotnet run 命令,应用程序将无法加载,并给出未找到文件的异常。

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

这是我的。

我也试过添加

"/appsettings.json":"${workspaceFolder}/appsettings.json"

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

请帮忙。

{
    // 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"
            }
        }
    ]
}

【问题讨论】:

    标签: c# asp.net json configuration appsettings


    【解决方案1】:

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

    更新

    没有意识到您正在使用 VS Code - 这个答案可能会对您有所帮助:https://stackoverflow.com/a/44378406/8532748

    【讨论】:

    • @HariKrishnaGaddipati 抱歉,没有意识到您正在使用 VS Code - 请参阅我的更新。
    • 这对我有帮助。我在一个文件夹中创建了一个 shell 脚本和一个批处理文件,并从 Task.json 中调用它们。因此,每当我的构建运行时,Task.json 中的所有任务都会被执行,因此如果当前操作系统是 Linux,它将执行 shell 脚本,如果当前操作系统是 Windows,它将运行批处理文件。
    猜你喜欢
    • 2020-01-24
    • 2017-07-12
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多