Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET core web API json configuration not copied to debug folder

I am working on an ASPNET core web API application. When I try to debug the application, the "appsetting.json" file is not copied to the debug folder. At this moment I am copying this file whenever I made changes. If I did not copy the file and I just run the dotnet run command, the application fails to load giving the file not found exception.

Should I do anything in the Launch.json file?

Here is what I have in mine.

I have also tried adding

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

in the "sourceFileMap" property in this JSON file but no use.

Please help.

{
    // 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"
            }
        }
    ]
}
like image 426
Hari Krishna Gaddipati Avatar asked Jan 21 '18 23:01

Hari Krishna Gaddipati


1 Answers

Right click on the file in object explorer, click on properties and change the value of "Copy to output directory". This is do not copy by default when you create the project but can be changed.

Update

Didn't realise you were using VS Code - this answer might help you: https://stackoverflow.com/a/44378406/8532748

like image 115
SBFrancies Avatar answered Oct 20 '22 15:10

SBFrancies