简体   繁体   English

启动时从引用项目中删除内容

[英]Content from referenced project being removed on startup

I am having an issue with content being removed from my output directory when I start the application. 启动应用程序时,从输出目录中删除内容时遇到问题。

In ProjectA I have no content files, only application-related things. 在ProjectA中,我没有内容文件,只有与应用程序相关的东西。

In ProjectB I have files Resources/js/x.js and Resources/js/y.js 在ProjectB中,我有文件Resources / js / x.jsResources / js / y.js

In ProjectC I have files Resources/js/z.js 在ProjectC中,我有文件Resources / js / z.js

All files have been set as "Content" and "Copy always". 所有文件均已设置为“内容”和“始终复制”。

ProjectA references ProjectB and ProjectC. ProjectA引用ProjectB和ProjectC。

When I build/rebuild/clean+rebuild the solution, the files x.js , y.js and z.js ends up in the output directory of ProjectA. 当我构建/重建/清理+重建解决方案时,文件x.jsy.jsz.js最终出现在ProjectA的输出目录中。 As it should; 正如它应该; everything is working fine. 一切都很好。

But when I click to start ProjectA, the file z.js is removed from the output directory . 但是,当我单击以启动ProjectA时,文件z.js 从输出目录中删除了

I have no pre-/post-build events, and there is nothing to see in the "Build" tab log. 我没有构建前/构建后事件,在“构建”选项卡日志中也看不到任何东西。 There is no code in the application to remove files either; 应用程序中也没有删除文件的代码。 and even if there were, it would make no sense why that file specifically is removed. 即使有,为什么专门删除该文件也没有意义。

Can somebody here help me figure out what is going on? 有人可以帮我弄清楚发生了什么吗?

Thanks in advance! 提前致谢!

First off, I created a solution with three projects, ProjectA referencing ProjectB and ProjectC as you describe, but could not reproduce your issue. 首先,我创建了一个包含三个项目的解决方案,即ProjectA引用了您所描述的ProjectB和ProjectC,但是无法重现您的问题。 I see a couple of possible solutions. 我看到了两种可能的解决方案。

  1. you can add x.js, y.js, and z.js files as links into ProjectA and then set the "Copy to Output Directory" property to "Copy Always" in ProjectA. 您可以将x.js,y.js和z.js 文件作为链接添加到ProjectA,然后在ProjectA中将“复制到输出目录”属性设置为“始终复制”。 In this way ProjectA will force the copy to the ouput directory instead of depending on the referenced projects to copy files on its behalf. 这样,ProjectA将强制将副本复制到ouput目录,而不是依赖于引用的项目代表其复制文件。

  2. Run the ProjectA.exe outside of VS2013 and connect the debugger after startup using Debug->Attach to Process... 在VS2013外部运行ProjectA.exe并在启动后使用Debug-> Attach to Process连接调试器...

  3. (not really recommended in your case but an option) You could switch the files to be embedded resources and then write them to disk at runtime using some code like the following: (在您的情况下,实际上不建议使用,但可以选择)您可以将文件切换为嵌入式资源,然后在运行时使用如下代码将其写入磁盘:

     static void Main(string[] args) { var assembly = Assembly.GetExecutingAssembly(); var resourceName = "readEmbeddedResourceFile.Resources.MyFile.txt"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { if (null != stream) { byte[] b1 = new byte[stream.Length]; // creat an array to hold the file stream.Read(b1, 0, (int)b1.Length); // read the file from the embedded resource File.WriteAllBytes("MyFile.txt", b1); // write the file to the current execution directory } } } 

Since Start generally builds any out of date projects is it possible that this partial build is somehow causing the file to be removed? 由于Start通常会生成任何过时的项目,因此这种部分生成是否有可能导致文件被删除? You might browse your Options->Projects and Solutions->Build and Run to see if one of those settings might help to resolve the issue. 您可以浏览“选项”->“项目和解决方案”->“构建并运行”,以查看这些设置之一是否可以帮助解决问题。 Here's what mine looks like (no file deletion) 这是我的样子(不删除文件) 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio不从间接引用的项目复制内容文件 - Visual studio not copying content files from indirectly referenced project 引用的项目依赖项DLL不被复制 - Referenced project dependencies DLL are not being copied 无法加载程序集“CommonBaseData”。 确保它被启动项目“CommonBaseType”引用 - Could not load assembly 'CommonBaseData'. Ensure it is referenced by the startup project 'CommonBaseType' 无法加载程序集...确保它被启动项目引用 - Could not load assembly... Ensure it is referenced by the startup project GameObject 没有从列表中删除? - GameObject not being removed from List? 安装/部署项目:防止在卸载时删除已修改的文件 - Setup/Deployment project: Prevent modified files from being removed when uninstalling 从电子邮件正文中删除了换行符 - Line breaks being removed from email body 逗号未按预期从字符串中删除 - comma not being removed as expected from string 如何防止“抽绳”被去除? - How to prevent “drawstring” from being removed? 如何检测正在从文件夹中删除的文件 - How to detect a file being removed from folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM