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

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

问题描述

我有一个C#项目,名为MyProject.csproj,位于"C:\ Projects \ MyProject \".我也有一些文件要复制到该项目的输出目录中.但是,文件位于"C:\ MyContentFiles \"位置,即它们不在项目区域内.该目录也具有子目录.目录的内容不受管理.因此,我必须包括其下的所有内容.

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

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

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

解决方案

您需要将文件添加为链接:

  1. 右键单击VS中的项目.
  2. 添加->现有项目...
  3. 查找文件.
  4. 选择它,然后
  5. 添加作为链接(在对话框的添加"按钮中下拉).
  6. 打开文件的属性,并将复制到输出目录"设置为始终复制".

但是您不能为目录树执行此操作.
相反,您需要为此编写后构建任务. 这是一个示例,可以让您凝视. /p>

I have a C# project say MyProject.csproj located at "C:\Projects\MyProject\". 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?

解决方案

You need to add file as a link:

  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天全站免登陆