Automate/Execute multiple ASP.NET Core commands

2019-05-04 00:39发布

问题:

How to automate/execute multiple ASP.NET Core commands in Visual Studio Code?

For example, execute dotnet clean,dotnet restore, dotnet build etc in a single go..


I was going to ask this question but instead found a solution for the same. So sharing this with the community.

回答1:

If you are using Visual Studio Code to develop ASP.NET Core apps you can automate dotnet restore, dotnet build, dotnet run, dotnet clean commands using a short one with the help of doskey.

doskey c = dotnet clean
doskey b = dotnet build
doskey r = dotnet restore
doskey rr = dotnet run
doskey p = dotnet publish -c release -r centos.7-x64 (NOTE: Here centos is the target OS)

Now, by entering c, b, r, rr or p will execute their respective command(s) on the integrated terminal window of Visual Studio Code. You can bind multiple commands together using $T. For eg:

doskey cb = dotnet clean $T dotnet build $T echo ************ DONE ************
doskey crb = dotnet clean $T dotnet restore $T dotnet build $T echo ************ DONE ************
doskey crbr = dotnet clean $T dotnet restore $T dotnet build $T dotnet run $T echo ************ DONE ************
doskey crbp = dotnet clean $T dotnet restore $T dotnet build $T dotnet publish - c release -r centos.7-x64 $T echo ************ DONE ************
doskey cbp = dotnet clean $T dotnet build $T dotnet publish -c release -r centos.7-x64 $T echo ************ DONE ************

Entering cb, crb, crbr, crbp or rbp will execute their respective multi-command(s).


These shortcuts will flush away when Visual Studio Code is restarted so to keep them persistent, save these commands as a batch file(eg: doskey.bat), and then open your usersettings.json file in Visual Studio Code and add these lines (these settings are for Command Prompt as terminal window) :

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
    "/K C:\\Users\\Username\\Desktop\\doskey.bat"
    // replace the path with your batch file, also remember to keep the "/K" flag
],