After moving my .NET Core project into a subfolder in the solution I am no longer able to Debug it using VS Code.
If I move tasks.json
and launch.json
into the project folder and open VS Code there I am able to debug, but I would like to be able to open the entire solution in VS Code.
The error message I am getting is this:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
The error seems to state that my task runner can no longer find my project, so I tried adding this to tasks.json
:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
],
// My addition
"options": {
"cwd": "${workspaceRoot}/myProjectFolder"
}
}
Doing this I am able to start the task, but I then get the following error:
Exception thrown: 'System.IO.FileNotFoundException' in
Microsoft.Extensions.Configuration.FileExtensions.dll
How do I configure the .NET Core debugger to be able to run a project that resides in a sub folder?
The reason for the FileNotFoundException pointed by mrtedweb, the program not finding the
appsettings.json
can be solved without changing the program code.Just edit
launch.json
, modifying thecwd
configuration to point to the project subfolder instead of the root workspace which is the default, fromcwd: ${workspaceRoot}
to,${workspaceRoot}/TheProject
.With this launch.json, it's possible to run the application from VS Code opening it from a root solution folder with the project inside a subfolder.
And it can also be run from the commandline without changing the paths in the program from the project subfolder.
The problem is your
tasks.json
, you should copy your subfolder.vscode/tasks.json
in the parent directory.When you create your
tasks.json
from the parent directory, it make atasks.json
like as yourtasks.json
example.But if you copy the
tasks.json
created in the subfolder It should be some like this:So there is the
.csproj
file, it say in the error.It can no longer locate the appsettings.json file since the project was moved to a subfolder. This can be easily fixed in the StartUp.cs file by adding the following variable to the constructor:
Note: You will need to specify the value for
<project folder name>
.Then update the line that reads
to read:
Also, verify the launch.json file is targeting the proper program file.
Note: You will need to specify the values for
<project name>
, and<program name>
.