Word 文件从“解决方案项目"中消失在 VS2010 [英] Word files disappear from "Solution Items" in VS2010

查看:36
本文介绍了Word 文件从“解决方案项目"中消失在 VS2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 VS2010 时遇到了问题(它也存在于最新版本 SP1 (10.0.40219.1) 中):

I've run into a problem with VS2010 (it also exists in the latest version, SP1 (10.0.40219.1)):

  • 将现有的 Word 文件添加到解决方案项"并签入这个新文件.
  • 检出文件进行编辑
  • 双击该文件并在 Word 中对其进行编辑(只需进行一些小改动)
  • 保存文件 (CTRL-S)
  • 现在该文件已从 Visual Studio 的解决方案项"中删除(您可能需要重复编辑和保存几次)

更新:我使用的是 Visual SourceSafe 2005.

尽管我进行了研究,但除了 此 Microsoft 页面,我想知道是否有办法防止此问题发生.

Despite my research efforts I haven't really found anything on this issue apart from this Microsoft page, and I'd like to know whether there is a way to prevent this problem from happening.

任何想法都非常受欢迎,提前致谢.

Any ideas are more than welcome, thanks in advance.

G.

推荐答案

经过进一步调查,我想我找到了这种行为背后的原因和解决方法.

After further investigation I think I found the reason behind this behaviour and a workaround.

另请注意,原始问题中描述的行为仅适用于直接添加到解决方案下方或直接添加到解决方案下方的文件夹中的文件.

原因

我不确定以下是否 100% 正确,但重点是 Word(可能还有其他 MS Office 应用程序)如何保存现有文件:

I'm not sure whether the following is 100% correct, but the main point is how Word (and probably other MS Office apps as well) saves an existing file:

  • 将文件的当前版本保存到临时文件
  • 重命名原始文件,以便以后出现问题时可以使用
  • 将临时文件复制到原文件所在的位置,使用原文件名
  • 删除原始文件(在第 2 步中重命名)

Visual Studio 发现该文件不存在(尽管时间很短)并将其从其树和 .sln 文件中删除.这也可以通过手动添加任何类型的文件、签出(如果未签出)、将其重命名为不同的名称然后恢复到其原始名称来重现 => 文件不再显示在 Visual Studio 中.

Visual Studio picks up that the file doesn't exist (for a very short time though) and removes it from its tree and the .sln file. This can also be reproduced by manually adding any kind of file, checking it out (if not checked out), renaming it to a different name and then back to its original name => file is no longer shown in Visual Studio.

解决方法

我按照 Microsoft 网站上的步骤创建了一个空的项目模板.我还将输出设置为类库",这样即使不存在静态 main 方法,项目也能编译.此模板可用于将文档"项目添加到现有解决方案.在此项目下,您可以根据需要添加文件并对其进行编辑,因为 Visual Studio 的行为有所不同,并且在将文件保存在此星座中时不会删除该文件.

I've created an empty project template following the steps on Microsoft's site. I also set the output to "Class Library" so that the project would compile even if no static main method exists. This template can be used to add a "Documentation" project to an existing solution. Underneath this project you can add files and edit them as you wish, as Visual Studio behaves differently and does not remove the file when it is saved in this constellation.

显然这种方法仍然不是很令人满意或优雅,但我希望它可以帮助其他可能遇到同样问题的人.

Obviously this approach is still not very satisfying or elegant, but I hope that it may be helpful for others who might run into the same problem.

G.

这篇关于Word 文件从“解决方案项目"中消失在 VS2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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