Word files disappear from “Solution Items” in VS2010

血红的双手。 提交于 2019-12-01 12:33:29

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

Please also note that the behaviour described in the original question only occurs for files that are added directly underneath a solution or to a folder that is directly underneath a solution.

The reason

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:

  • Save the current version of the file to a temporary file
  • Rename the original file so it can be used later in case something goes wrong
  • Copy the temporary file to the location of the original file, using the original file's name
  • Delete the original file (that was renamed in step 2)

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.

The workaround

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.

I've run into the same issue. I simply undo changes for the solution after I've closed the document file and the solution files will be as they originally were before your document changes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!