Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get the message ''could not find the task 'build'" when I try to start my C# code

Tags:

c#

.net-core

I am new to C# and am learning using pluralsight

I have followed exactly what the tutorials are doing but have ran into a problem that the tutorial does not.

I have the simple ''Hello World'' program built when you make C# code via .Net

In Visual Studio Code, if go with Start Debugging or Start Without Debugging, the following error pops up

''could not find the task 'build'"

I then click on debug anyway then the following error shows up

launch:program dir \ < insert-project-name-here >.dll does not exist there is an option to open launch.json

the confusing thing is, the .dll file DOES exist...

Further, checking launch.json, I have the following:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (console)",
      "type": "coreclr",
      "request": "launch",
      "WARNING01": "*********************************************************************************",
      "WARNING02": "The C# extension was unable to automatically decode projects in the current",
      "WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
      "WARNING04": "been created as a placeholder.",
      "WARNING05": "",
      "WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
      "WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
      "WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
      "WARNING09": "If this allows OmniSharp to now load your project then --",
      "WARNING10": "  * Delete this file",
      "WARNING11": "  * Open the Visual Studio Code command palette (View->Command Palette)",
      "WARNING12": "  * run the command: '.NET: Generate Assets for Build and Debug'.",
      "WARNING13": "",
      "WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
      "WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
      "WARNING16": "button at the bottom of this file.",
      "WARNING17": "*********************************************************************************",
      "preLaunchTask": "build",
      "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
      "args": ["link"],
      "cwd": "${workspaceFolder}",
      "console": "internalConsole",
      "stopAtEntry": false
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ]
}
like image 702
JoyFulCode Avatar asked Jul 04 '19 19:07

JoyFulCode


People also ask

How do I open Task Vscode?

Tip: You can run your task through Quick Open (Ctrl+P) by typing 'task', Space and the command name.

How do I open a task in Visual Studio?

To open Task List, select View > Task List, or from the keyboard press Ctrl+\,T.


1 Answers

The easy way

In VS Code, after you've loaded the code base. Bring up the command pallet and enter > .NET Generate Assets for Build and Debug then hit return/enter.

This will force VS Code to recreate the launch.json and task.json files.

Keep an eye on the lower-left corner of the VS Code window for a toast message which looks like this:

screenshot of VS Code showing a toast message asking for confirmation when recreating build and debug assets

and ensure that you click Yes

The complicated way

You need to alter the line in your task.json file which currently reads:

"program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",

replacing <insert-target-framework-here> with the target framework moniker in your csproj, which might look like something similar to this:

<TargetFramework>netcoreapp2.1</TargetFramework>

You'll also need to replace the <insert-project-name-here>.dll string with the name of your produced DLL.

like image 90
Jamie Taylor Avatar answered Sep 17 '22 14:09

Jamie Taylor