C# PostBuildEvent 创建目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10508778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:07:48  来源:igfitidea点击:

PostBuildEvent Create Directory

c#visual-studio-2010cmdpost-build-event

提问by Deepak

I'm trying to create a folder named Design in the build output folder using th following commandline in the PostBuildEvent in visual studio

我正在尝试在 Visual Studio 的 PostBuildEvent 中使用以下命令行在构建输出文件夹中创建一个名为 Design 的文件夹

mkdir $(TargetDir)Design  ....Runs Successfully but folder is not created
mkdir "$(TargetDir)Design" ....Runs Successfully but folder is not created
MD $(TargetDir)Design  ....Runs Successfully but folder is not created
MD "$(TargetDir)Design"  ....Runs Successfully but folder is not created

Can anyone tell me what I'm doing wrong

谁能告诉我我做错了什么

采纳答案by Eric

You need to do something like:

您需要执行以下操作:

if not exist DirToCreate mkdir DirToCreate

回答by user2444499

This worked for me (where Design is the folder you want to create):

这对我有用(其中 Design 是您要创建的文件夹):

mkdir $(TargetDir)\Design

If you want to check for existence first:

如果您想先检查是否存在:

if not exist $(TargetDir)\Design mkdir $(TargetDir)\Design

回答by Invvard

In addition to the two previous answers, you could use a variable like this :

除了前面的两个答案之外,您还可以使用这样的变量:

SET path=$(TargetDir)\Design
if not exist "%path%" mkdir "%path%"

That way, you'll avoid any duplication. (Tested with VS2019)

这样,您将避免任何重复。(用VS2019测试)