Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code needs explicit clean and build

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?)
like image 372
Lost Avatar asked Jun 21 '18 23:06

Lost


People also ask

How do you do a clean build in VS Code?

On the menu bar, choose Build, and then choose either Build ProjectName or Rebuild ProjectName. Choose Build ProjectName to build only those project components that have changed since the most recent build. Choose Rebuild ProjectName to "clean" the project and then build the project files and all project components.

How do I clean up and build in Visual Studio?

To build, rebuild, or clean an entire solutionChoose Build All to compile the files and components within the project that have changed since the most recent build. Choose Rebuild All to "clean" the solution and then builds all project files and components. Choose Clean All to delete any intermediate and output files.

What is the difference between build and clean?

Clean Solution - deletes all compiled files (all dll's and exe's ). Build Solution - compiles code files (dll and exe) that have changed. Rebuild Solution - Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.


1 Answers

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.

like image 98
Shaun Luttin Avatar answered Oct 14 '22 07:10

Shaun Luttin