C# 预构建事件:使用 XCopy 将文件夹及其子文件夹和文件复制到构建目录中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12577496/
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
Pre Build Event: Copy Folder and it's SubFolders and files into Build Directory using XCopy
提问by Jignesh Thakker
I have Window Application and I have some plugins & it's ChildPlugins which I placed in My Application folder structure(see folder structure image). I used SVN as source control so, every folder has .SVNfolder.
我有窗口应用程序,我有一些插件,它是我放置在我的应用程序文件夹结构中的 ChildPlugins(参见文件夹结构图像)。我使用 SVN 作为源代码控制,所以每个文件夹都有.SVN文件夹。
Here is My Question:
这是我的问题:
Below image is my directory structure for Plugins. All folder have some files related it plugins. Now I want to copy all folder (with SubFolders) & it's files to my Application Build output path by using Pre Built Event.
下图是我的插件目录结构。所有文件夹都有一些与它的插件相关的文件。现在我想使用预构建事件将所有文件夹(带有子文件夹)及其文件复制到我的应用程序构建输出路径。


After searching on net I found that by using XCopy I can achieve what I want. By using below code I can copy Plugins directory & it's files but can't able to copy it's sub folders & Sub folder Files .
在网上搜索后,我发现通过使用 XCopy 我可以实现我想要的。通过使用下面的代码,我可以复制 Plugins 目录及其文件,但无法复制它的子文件夹和子文件夹 Files 。
xcopy "$(SolutionDir)Plugins\*.*" "$(SolutionDir)Windows\Host\Host.GUI\bin\x86$(ConfigurationName)\Plugins\" /Y/D
I want to copy Folder & it's all subfolders with all files and want to exclude .SVN. Can anyone point me How can I do this?
我想复制 Folder & 它是包含所有文件的所有子文件夹,并且想要排除.SVN. 谁能指出我该怎么做?
Thanks.
谢谢。
采纳答案by CrazyCasta
You need to add the /E switch to copy subdirectories (including Empty ones).
您需要添加 /E 开关来复制子目录(包括空目录)。
回答by Mario Berthely
I have used this:
我用过这个:
xcopy "$(ProjectDir)MyFolder\*.*" "$(SolutionDir)ConsoleApplication1\bin\Release\MyFolder" /Y /I /E
And worked fine, the folder 'MyFolder' appear into my 'Release' folder when I compile the project with all the documents in it.
并且工作正常,当我编译包含所有文档的项目时,文件夹“MyFolder”出现在我的“Release”文件夹中。
Something to point out here is that the path that is after $(SolutionDir) would change depending of the name of your solution, my solution is ConsoleApplication1.
这里需要指出的是,$(SolutionDir) 之后的路径会根据解决方案的名称而改变,我的解决方案是 ConsoleApplication1。
回答by Adam Finley
Better if it doesn't require a path with solution name or configuration type:
如果不需要具有解决方案名称或配置类型的路径,则更好:
xcopy "$(ProjectDir)MyFolder\*.*" "$(TargetDir)\MyFolder" /Y /I /E
回答by Artiom
Here is an example of copying Assets folder (located in the project folder) into bin(debug or release ...)\Assets
这是将 Assets 文件夹(位于项目文件夹中)复制到 bin(debug or release ...)\Assets 的示例
<Target Name="BeforeBuild">
<Exec Command="xcopy "$(ProjectDir)Assets\*.*" "$(ProjectDir)bin$(Configuration)\Assets" /Y /I /E" />
</Target>
Note, double quotes are replaced with a special word
注意,双引号用特殊词代替

