20

So, I am an old school Visual Studio user who just got migrated to Visual Studio Code and I think I am missing something here. However, I will explain what I am experiencing here:

With Visual Studio I could always right-click a solution and rebuild it and run it and it was really great. However, in Visual Studio Code, there is no rebuild (at least that I know of). So now I have to do dotnet clean followed by dotnet clean and since it is a multi-step process, I sometimes forget a step and then my code starts behaving really whimsically. For example, a code like below

Person.Name = someNameVariable 

if this was just a new added line in my code then V-code would execute that line of code but when I put watch on Person.Name it is always Null. Now, This could be because it is still executing old code. However, the behavior is not very obvious and makes me feel like my code may have some issues. So I have two questions:

  1. Is there any easy way to have vs Code build and clean?
  2. If not, is there any way for VS Code to fail if I am running old code(or at least show me some warning?)
2
  • 1
    Are you looking for a way to click something that causes clean, build, and launch of the debugger all in one step? Jun 22, 2018 at 1:11
  • If possible, why not?
    – Lost
    Jun 22, 2018 at 1:21

1 Answer 1

22

Try a custom build task in your tasks.json.

Open VSCode settings and search for "terminal.integrated.shell".

If you are using PowerShell as your integrated terminal, then use the following build task in your tasks.json file.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "dotnet clean; dotnet build",
            "args": [
            ]
        }
    ]
}

If you are using cmd or bash as your integrated termininal, then change the command to this:

"command": "dotnet clean && dotnet build",

Then hit your VS Code debug button.

That assume you already have the default launch.json file with "preLaunchTask": "build" in it.

2
  • 1
    If I am not mistaken the file should be named tasks.json (by now) Jul 10, 2019 at 12:00
  • @DanielSteiner Nice catch. Fixed. Jul 10, 2019 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.