Reputation: 5493
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?
Upvotes: 4
Views: 8226
Reputation: 946
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 a tasks.json
like as your tasks.json
example.
But if you copy the tasks.json
created in the subfolder It should be some like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/<change to your subfolder>/<your project>.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
So there is the .csproj
file, it say in the error.
Upvotes: 6
Reputation: 1183
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 the cwd
configuration to point to the project subfolder instead of the root workspace which is the default, from
cwd: ${workspaceRoot}
to, ${workspaceRoot}/TheProject
.
// C:\Solution\.vscode\launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/TheProject/bin/Debug/netcoreapp1.1/TheProject.dll",
"args": [],
"cwd": "${workspaceRoot}/TheProject",
"stopAtEntry": false,
"console": "internalConsole",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5050"
}
}
]
}
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.
C:\Solution>code .
And it can also be run from the commandline without changing the paths in the program from the project subfolder.
C:\Solution\TheProject>dotnet run TheProject.csproj
Upvotes: 2
Reputation: 793
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:
var filePath = Path.Combine(env.ContentRootPath, "<project folder name>", "appsettings.json");
Note: You will need to specify the value for <project folder name>
.
Then update the line that reads
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
to read:
.AddJsonFile(filePath, optional: false, reloadOnChange: true)
Also, verify the launch.json file is targeting the proper program file.
"program": "${workspaceRoot}/<project name>/bin/Debug/netcoreapp1.1/<program name>.dll"
Note: You will need to specify the values for <project name>
, and <program name>
.
Upvotes: 0