Visual Studio Code needs explicit clean and build

余生颓废 提交于 2020-12-30 07:28:42

问题


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?)

回答1:


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.



来源:https://stackoverflow.com/questions/50978878/visual-studio-code-needs-explicit-clean-and-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!