如何防止在增量构建过程中删除内容文件? [英] How to prevent content files to be removed during incremental build?

查看:73
本文介绍了如何防止在增量构建过程中删除内容文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含3个项目的Visual Studio 2015 Update 3解决方案:

I have a Visual Studio 2015 Update 3 solution with 3 projects:

我的顶级应用程序是MyApp,它在ClassLibrary2上有一个项目引用,而在ClassLibrary1上又有一个项目引用:

My top-level application is MyApp which has a project reference on ClassLibrary2 which in turn has a project reference on ClassLibrary1:

MyApp -> ClassLibrary2 -> ClassLibrary1

ClassLibrary1具有一个数据文件data.bin,这是其正常执行所必需的.预计将在与执行应用程序时ClassLibrary1程序集所在的位置相对的Resources/子文件夹中找到此数据文件. ClassLibrary1的结构类似于:

The ClassLibrary1 has a data file, data.bin, that is required for its normal execution. It is expected that this data file will be found in a Resources/ sub-folder relative to where the ClassLibrary1 assembly is when the application is executed. The structure of the ClassLibrary1 is similar to:

ClassLibrary1.csproj
    Resources/
        data.bin
    MyClassBehaviorDrivenByData.cs
    ...

data.bin文件的Build Action属性设置为Content(我也尝试过使用None),其Copy to Output Directory属性设置为Copy If Newer.

The data.bin file has its Build Action property set to Content (I have also tried with None) and its Copy to Output Directory set to Copy If Newer.

如果我执行完整的解决方案重建,则data.bin文件将按预期方式进入MyApp的输出目录.但是,如果我在MyApp项目中进行了一些更改并构建了解决方案,则会从MyApp的输出目录中删除文件(注意:输出"窗口仅显示<因为仅更改了MyApp的代码,所以构建了c0>.

If I do a full solution Rebuild, the data.bin file finds its way to the output directory of MyApp, as expected. However, if I do some changes in the MyApp project and build the solution, the data.bin file is deleted from the output directory of MyApp (note: the Output window shows that only MyApp is built since only the code of MyApp was changed).

解决方法:

  1. 每次构建MyApp时,我都可以使用MyApp中的构建后步骤将数据文件强制复制到输出目录中.但是,这违背了以下原则:开发人员拥有" ClassLibrary1如果添加新数据文件,修改现有文件或将其移至其他位置,则不必担心在消耗项目中修改构建后脚本.

  1. I could use post-build steps in MyApp to forcefully copy the data file to the output directory each time MyApp builds. However, this goes against the principle that the developer "owning" ClassLibrary1 should not have to worry about modifying post-build scripts in consuming projects if he adds a new data file, modify existing ones or move them elsewhere.

我可以直接从MyApp添加对ClassLibrary1的引用.但是,这违反了隐藏ClassLibrary2 API下的ClassLibrary1功能/API的愿望(即,我不希望ClassLibrary1 API泄漏到MyApp中).

I could directly add a reference to ClassLibrary1 from MyApp. However, this violates the desire to hide away the ClassLibrary1 functionality/API under the ClassLibrary2 API (i.e., I don't want ClassLibrary1 API to leak into MyApp).

我的问题是:是什么导致在MyApp的增量构建期间从MyApp的输出目录中删除data.bin文件,并且有一种方法可以防止这种情况发生,而无需使用列出的两种解决方法之一以上?

My questions are: what causes the data.bin file to be deleted from MyApp's output directory during incremental builds of MyApp and is there a way to prevent this to happen without using one of the 2 workarounds listed above?

推荐答案

我有同样的问题.

尽管我不太喜欢它,但我的解决方法是将文件data.bin包含在ClassLibrary2 probject中,并将复制到输出目录"设置为如果更新则复制".我还将ClassLibrary1中data.bin的相同属性设置为请勿复制".

My workaround, although I am not very fond of it, is including the file data.bin in the ClassLibrary2 probject and setting "Copy to Output Directory" to "Copy if newer". I also set the same property for data.bin in ClassLibrary1 to "Do not copy".

这篇关于如何防止在增量构建过程中删除内容文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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