5

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

1 Answers1

6

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

SBFrancies
  • 3,987
  • 2
  • 14
  • 37
  • @HariKrishnaGaddipati Sorry, didn't realise you were using VS Code - see my update. – SBFrancies Jan 21 '18 at 23:35
  • This helped me. I created a shell script and a batch file in a folder and called them from the Task.json. So whenever my build is run all the tasks in the Task.json will be executed so it will execute the shell script if the current OS is Linux or it will run the Batch file if the current OS is Windows. – Hari Krishna Gaddipati Mar 01 '18 at 16:28