在 .csproj 中包含项目锥之外的内容文件 [英] Including content files in .csproj that are outside the project cone

查看:16
本文介绍了在 .csproj 中包含项目锥之外的内容文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 项目,例如位于C:ProjectsMyProject"的 MyProject.csproj.我还有一些文件要复制到该项目的输出目录中.但是,这些文件位于C:MyContentFiles"位置,即它们不在项目锥内.该目录也有子目录.目录的内容不受管理.因此,我必须包括它下面的所有内容.

I have a C# project say MyProject.csproj located at "C:ProjectsMyProject". I also have files that I want copied into the output directory of this project. But, the files are at the location "C:MyContentFiles", i.e. they are NOT within the project cone. This directory has sub-directories as well. The contents of the directory is not managed. Hence I have to include all what is under it.

当我将它们作为内容"包含在项目中时,它们会被复制,但目录结构会丢失.我做了这样的事情:-

When I include them as 'Content' in the project, they are copied, but the directory structure is lost. I did something like this:-

<Content Include="....MyContentFiles**">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

如何将这些文件/目录递归复制到项目的输出目录中并保留目录结构?

How do I copy these files/directories recursively into the output directory of the project with the directory structure preserved?

推荐答案

需要添加文件为链接:

  1. 在VS中右键项目.
  2. 添加 -> 现有项目...
  3. 找到文件.
  4. 选择它然后.
  5. 添加作为链接(在对话框的添加按钮中下拉).
  6. 打开文件的属性,将复制到输出目录"设置为始终复制".
  1. Right click on the project in VS.
  2. Add -> Existing Item...
  3. Find the file.
  4. Select it and.
  5. Add as a Link (drop down in the Add Button in the dialog).
  6. Open the properties of the file and set "Copy to Output Directory" to "Copy always".

但是您不能为目录树执行此操作.
相反,您需要为此编写构建后任务.这是一个示例,会让您大开眼界.

BUT You cannot do it for the directory tree.
Instead you need to write post-build task for that. This is a sample that will get you stared.

这篇关于在 .csproj 中包含项目锥之外的内容文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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