发布项目时复制外部文件夹

时间:2015-10-15 14:32:16

标签: c# publish pubxml

我已从项目中排除了构建文件夹。 但是在发布项目时,我想将文件夹及其子文件夹内容复制到项目的根目录。如何将其包含在发布pubxml文件中?

1 个答案:

答案 0 :(得分:0)

使用相对路径

private String newPath(Int32 noOfLevels, String SourcePath) 
{

   String path = "";
   for(int i=0; i< noOfLevels; i++) {
     path+= "..\";
   }
   path += SourcePath;
   return path;
}

//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", 
    SearchOption.AllDirectories))
    Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));

//Copy all the files & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", 
    SearchOption.AllDirectories))
    File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);

发现于Copy the entire contents of a directory in C#

如果不使用相对路径,这将是一个重复的问题。

相关问题