I've been desperately looking for the answer to this and I feel I'm missing something obvious.
我一直在拼命寻找答案,我觉得我错过了一些明显的东西。
I need to copy a folder full of data files into the TARGETDIR of my deployment project at compile time. I can see how I would add individual files (ie. right click in File System and go to Add->File) but I have a folder full of data files which constantly get added to. I'd prefer not to have to add the new files each time I compile.
我需要在编译时将一个包含数据文件的文件夹复制到我的部署项目的TARGETDIR中。我可以看到我将如何添加单个文件(即右键单击文件系统并转到Add-> File)但我有一个文件夹,其中包含不断添加的数据文件。我不想每次编译时都要添加新文件。
I have tried using a PreBuildEvent to copy the files:
我尝试使用PreBuildEvent来复制文件:
copy $(ProjectDir)..\Data*.* $(TargetDir)Data\
复制$(ProjectDir).. \ Data *。* $(TargetDir)数据\
which fails with error code 1 when I build. I can't help but feel I'm missing the point here though. Any suggestions?
我构建时失败,错误代码为1。我不禁觉得自己错过了这一点。有什么建议?
Thanks in advance.
提前致谢。
Graeme
5 个解决方案
#1
Went to this route.
去了这条路。
- Created a new project (deleted the default source file Class1)
- Added the files/folders necessary to the project.
- Added the project as project output in the installer, choosing the option content files.
创建了一个新项目(删除了默认的源文件Class1)
添加了项目所需的文件/文件夹。
在安装程序中将项目添加为项目输出,选择选项内容文件。
This removes the complexity of having to zip/unzip the files as suggested earlier.
这消除了必须按照之前的建议压缩/解压缩文件的复杂性。
#2
Try
xcopy $(ProjectDir)..\Data\*.* $(TargetDir)Data /e /c /i [/f] [/r] /y
xcopy $(ProjectDir).. \ Data \ *。* $(TargetDir)Data / e / c / i [/ f] [/ r] / y
/e to ensure tree structure fulfilment (use /s if you want to bypass empty folders)
/c to continue on error (let the build process finish)
/i necessary to create the destination folder if none exists
/y assume "yes" for overwrite in case of previously existing files
/ e确保树结构实现(如果你想绕过空文件夹,则使用/ s)/ c继续出错(让构建过程完成)/如果不存在则创建目标文件夹是必要的/ y假定为“是”在先前存在的文件的情况下覆盖
[optionnal]
/f if you wanna see the whole pathes resulting from the copy
/r if you want to overwrite even previously copied read-only files
[optionnal] / f如果你想看到复制/ r产生的整个pathes,如果你想要覆盖以前复制的只读文件
The method is simpler on the project than on files, yes. Beside, on files, it copies only the modified/missing files on each build but forces you to maintain the project on each data pack modification. Depends on the whole data size and the variability of your data pack.
该方法在项目上比在文件上更简单,是的。此外,在文件上,它仅复制每个构建中的已修改/缺失文件,但强制您在每个数据包修改时维护项目。取决于整个数据大小和数据包的可变性。
Also beware the remaining files if you remove some from your data pack and rebuild without emptying your target folder.
如果从数据包中删除一些文件并重建而不清空目标文件夹,也要注意剩余的文件。
Good luck.
#3
I solved the problem by a workaround:
我通过解决方法解决了这个问题:
- Add a build action of packaging entire directory (could be filtered) to a ZIP file.
- Add a reference to an empty ZIP file to deployment project.
- Add a custom action to deployment project to extract the ZIP to destination folder.
添加将整个目录(可以过滤)打包到ZIP文件的构建操作。
将空ZIP文件的引用添加到部署项目。
向部署项目添加自定义操作以将ZIP解压缩到目标文件夹。
It's simple and stable.
它简单而稳定。
#4
Your error is probably because your path has spaces in it and you don't have the paths in quotes.
您的错误可能是因为您的路径中包含空格而您没有引号中的路径。
ex copy "$(ProjectDir)..\Data*.*" "$(TargetDir)Data\"
ex copy“$(ProjectDir).. \ Data *。*”“$(TargetDir)Data \”
I need to do a similar thing. Thinking a custom action...
我需要做类似的事情。想一个自定义动作......
#5
I found a different workaround for this. I added a web project to my solution that points at the data directory I want included in the deployment project. The web project automatically picks up any new files in the data directory and you can refer to the project content in the deployment project.
我找到了一个不同的解决方法。我在我的解决方案中添加了一个Web项目,该项目指向我想要包含在部署项目中的数据目录。 Web项目会自动获取数据目录中的所有新文件,您可以参考部署项目中的项目内容。
#1
Went to this route.
去了这条路。
- Created a new project (deleted the default source file Class1)
- Added the files/folders necessary to the project.
- Added the project as project output in the installer, choosing the option content files.
创建了一个新项目(删除了默认的源文件Class1)
添加了项目所需的文件/文件夹。
在安装程序中将项目添加为项目输出,选择选项内容文件。
This removes the complexity of having to zip/unzip the files as suggested earlier.
这消除了必须按照之前的建议压缩/解压缩文件的复杂性。
#2
Try
xcopy $(ProjectDir)..\Data\*.* $(TargetDir)Data /e /c /i [/f] [/r] /y
xcopy $(ProjectDir).. \ Data \ *。* $(TargetDir)Data / e / c / i [/ f] [/ r] / y
/e to ensure tree structure fulfilment (use /s if you want to bypass empty folders)
/c to continue on error (let the build process finish)
/i necessary to create the destination folder if none exists
/y assume "yes" for overwrite in case of previously existing files
/ e确保树结构实现(如果你想绕过空文件夹,则使用/ s)/ c继续出错(让构建过程完成)/如果不存在则创建目标文件夹是必要的/ y假定为“是”在先前存在的文件的情况下覆盖
[optionnal]
/f if you wanna see the whole pathes resulting from the copy
/r if you want to overwrite even previously copied read-only files
[optionnal] / f如果你想看到复制/ r产生的整个pathes,如果你想要覆盖以前复制的只读文件
The method is simpler on the project than on files, yes. Beside, on files, it copies only the modified/missing files on each build but forces you to maintain the project on each data pack modification. Depends on the whole data size and the variability of your data pack.
该方法在项目上比在文件上更简单,是的。此外,在文件上,它仅复制每个构建中的已修改/缺失文件,但强制您在每个数据包修改时维护项目。取决于整个数据大小和数据包的可变性。
Also beware the remaining files if you remove some from your data pack and rebuild without emptying your target folder.
如果从数据包中删除一些文件并重建而不清空目标文件夹,也要注意剩余的文件。
Good luck.
#3
I solved the problem by a workaround:
我通过解决方法解决了这个问题:
- Add a build action of packaging entire directory (could be filtered) to a ZIP file.
- Add a reference to an empty ZIP file to deployment project.
- Add a custom action to deployment project to extract the ZIP to destination folder.
添加将整个目录(可以过滤)打包到ZIP文件的构建操作。
将空ZIP文件的引用添加到部署项目。
向部署项目添加自定义操作以将ZIP解压缩到目标文件夹。
It's simple and stable.
它简单而稳定。
#4
Your error is probably because your path has spaces in it and you don't have the paths in quotes.
您的错误可能是因为您的路径中包含空格而您没有引号中的路径。
ex copy "$(ProjectDir)..\Data*.*" "$(TargetDir)Data\"
ex copy“$(ProjectDir).. \ Data *。*”“$(TargetDir)Data \”
I need to do a similar thing. Thinking a custom action...
我需要做类似的事情。想一个自定义动作......
#5
I found a different workaround for this. I added a web project to my solution that points at the data directory I want included in the deployment project. The web project automatically picks up any new files in the data directory and you can refer to the project content in the deployment project.
我找到了一个不同的解决方法。我在我的解决方案中添加了一个Web项目,该项目指向我想要包含在部署项目中的数据目录。 Web项目会自动获取数据目录中的所有新文件,您可以参考部署项目中的项目内容。