如何在 Windows 中的 Visual Studio Code tasks.json 中创建目录? [英] How to create a directory in Visual Studio Code tasks.json in windows?

查看:99
本文介绍了如何在 Windows 中的 Visual Studio Code tasks.json 中创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 mkdir 命令为 windows 用户编写一个使用 Visual Studio Code 任务(在 tasks.json 中)创建目录的任务,它运行良好除非文件夹已存在.

I'm trying to write a task to create a directory using Visual studio Code tasks (in tasks.json) for windows users using the mkdir command, it's working well except when the folder already exists.

tasks.json

{
    "label": "(release) create build directory",
    "type": "shell",
    "linux": {
        "command": "mkdir -p ./build/release"
    },
    "windows": {
        "command": "mkdir .\\build\\release", // Not working when folder already exists !
    }
},

我的尝试:
"command": "IF NOT EXIST .\\build\\release mkdir .\\build\\release"
但后来我得到了错误:

What I tried:
"command": "IF NOT EXIST .\\build\\release mkdir .\\build\\release"
But then I get the error:

At line:1 char:3
+ IF NOT EXIST .\build\release mkdir .\build\release
+   ~
Missing '(' after 'IF' in if statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingOpenParenthesisInIfStatement

如果不能这样做,是否可以通过忽略退出代码来运行此任务?(以便任务继续构建我的项目)

If it is not possible to do it this way, is it possible to run this task by ignoring the exit code ? ( so that the tasks continue to build my project)

环境:
Visual Studio 代码 1.40.2
Windows 10 专业版 x64

Environment:
Visual Studio code 1.40.2
Windows 10 Pro x64

推荐答案

我找到了一种方法,通过使用 cmd.exe/C 选项(运行命令然后终止)

I found a way of doing it by using cmd.exe with /C option (Run Command and then terminate)

{
    "label": "(release) create build directory",
    "type": "shell",
    "linux": {
        "command": "mkdir -p ./build/release"
    },
    "windows": {
        "command": "cmd",
        "args": ["/C", "if not exist .\\build\\release mkdir .\\build\\release"]
    }
},

这篇关于如何在 Windows 中的 Visual Studio Code tasks.json 中创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆