Is there a way to prevent Visual Studio from automatically removing solution items?
-
2012年3月2日 16:43
Steps to reproduce (Visual Studio 2010 Ultimate, Version 10.0.40219.1 SP1Rel)
1. Create a new visual studio project/solution. I created a C# console application.
2. Copy an Excel file into the source code folder.
3. Right click on the solution in the solution explorer, and select "Add > Existing Item..."
4. Select the excel file copied above. Visual studio adds it to a "Solution Items" folder.
5. Double click on the solution items entry. Excel launches.
6. In Excel, click "Save".
RESULT: Visual studio removes the excel file from the "Solution Items" folder.
Is there any way to prevent visual studio from doing this? Note that opening the file external to visual studio also causes the same problem.
Is this a bug? Is there a way to prevent this behavior? It seems to me that visual studio removing files I explicitly have added from the solution is a bad thing.
This is a problem because we are using the data in the excel workbook as part of the build process.
T.Tobler
- 已编辑 T.Tobler 2012年3月2日 16:44
全部回复
-
2012年3月3日 1:12Hi T.Tobler, I just tried the steps on my side and the work book is not being deleted after I open it from VS, make some changes and save it. Have you tried reproducing this on another machine to see if you get the same behaviour?
-
2012年3月5日 9:22版主
Hi T.Tobler,
Welcome to the MSDN forum.
I followed your steps and I didn’t reproduce your issue. It seems that your Visual Studio are running with some error. So I suggest you try this command to solve your issue:
- Open Visual Studio Command Prompt (2010) under Start menu -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools (run it with Administrator privilege: right-click the program -> Run as administrator);
-
Try some devenv switches in command prompt:
- Run devenv /Resetsettings to eliminate the cause of corrupted settings.
- Run devenv /ResetSkipPkgs in Command Prompt.
- Run devenv /Safemode to see if you can apply it correctly. This can eliminate the possibility that third party Add-ins or packages are causing problems.
- Reboot the machine in Safe Mode. This can isolate some third party application/driver's interference.
- Switch and try a new user account. This can rule out the possibility of corrupted user profile.
- You can repair your Visual Studio by using the installation package.
If you still can encounter this, please collect some logs with devenv.exe /log <log path> in Command Prompt. The log files will be generated in the <log path>. Then you can check and analyze the log file to see if there is anything incorrect. After that, you can also post your log file to a public site, like SkyDrive, and post the link here so that I can help you.
Best regards,
Barry Wang [MSFT]
MSDN Community Support | Feedback to us
-
2012年3月5日 13:10
Thanks for looking into this, Barry.
To answer the question as to whether this can be seen on other machines and for other users -- Yes. Every development machine that we have in house easily reproduces this problem (~8 machines with individual users, all using Visual Studio Ultimate 2010). It is an issue when other developers did not realize it was removed, and they check in the file into the TFS source control repository, requiring that someone else come back in and fix it.
This issue has been occuring for several years (2 or 3). We've normally tried to correct it by requiring developers to turn on "prompt before checking out", and when visual studio tries to automatically check out the solution file so it can remove the excel file entry, we've asked they cancel it. However, as we have added developers, and created parallel development branches, it is more often the case that the solution file will already be checked out, and visual studio makes this change without prompting in this scenario.
I do not understand why you cannot reproduce this; if there is in fact a way to prevent it from occuring, I'd be interested in knowing the exact steps you performed... Are you sure you are adding it as a solution item, and not as an item under the project itself?
*NOTE: I just ran a quick test to see if perhaps a misunderstanding of the steps to reproduce has the same problem - It appears that if you add the excel file to a project, instead of as a solution level item, that visual studio will not remove it. I'll have to see if we can create a dummy project to hold our solution level items; this may be an adequate workaround for this bug.
In any case, I've attached the log as you suggested. I did not see anything out of ordinary; it did not seem to log the fact that I edited the xls file at all. It can be examined at:
T.Tobler
- 已编辑 T.Tobler 2012年3月5日 13:12
-
2012年3月6日 7:23版主
Hi T.Tobler,
This is what I did to my project:
This is the result:
I also tried to add a XLS file to the project instead of the solution. The file hasn’t been removed.
Then I tried to read your logs. I found this warning:
268
Warning
Found templates with duplicate template ids at "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\Web\CSharp\1033\ReportApplication.zip\ReportsApplication.vstemplate" and "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\Web\VisualBasic\1033\ReportApplication.zip\ReportsApplication.vstemplate"
VisualStudio
To
335
Warning
Found templates with duplicate template ids at "C:\Users\ttobler\AppData\Local\Microsoft\VisualStudio\10.0\ProjectTemplatesCache_{F7C58D98-20C6-4193-B548-159E9461AF02}\CSharp\Extensibility\CSharp.VSPackageUnitTest.zip\Package.UnitTest.vstemplate" and "C:\Users\ttobler\AppData\Local\Microsoft\VisualStudio\10.0\ProjectTemplatesCache_{F7C58D98-20C6-4193-B548-159E9461AF02}\VisualBasic\Extensibility\VisualBasic.VSPackageUnitTest.zip\Package.UnitTest.vstemplate"
VisualStudio
According to the Visual Studio error log, it seems like Visual Studio could not load templates correctly, or the templeates file has corrupted.
Please open Windows Explorer, navigate to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\, check the ProjectTemplates, ItemTemplates and their subfolders to see if the template files exists.
Then pleasae delete ItemTemplatesCache, ProjectTemplatesCache folder, run the devenv /InstallVSTemplates and devenv /Setup command again. If this still not working, would you please collect Visual Studio log with /log command, and send it to me?
Also, VS will register Project and Item templates information into your local registry, please check whether or not these keys exists in your local registry:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\VSTemplate\Project;
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\VSTemplate\Item;
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\VSTemplate\Item;
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\VSTemplate\Project;
Above are some common steps to solve template issues. But in case more than one user has the same issue, maybe you should check that if you are using some corrupt templates.
If there are any updates, please feel free to let me know.
Best regards,
Barry Wang [MSFT]
MSDN Community Support | Feedback to us
-
2012年3月6日 13:37
Hi Barry,
Thanks again for looking into this. I tried following your procedure to reset the templates. After completing your suggestions, I ran the steps again (same issue occurs), and examined the log file... it still had the same "..duplicate template ids.." messages.
In your procedure, you did not indicate that you actually tried editing and saving the excel file. In my tests, visual studio does not remove the file until the point where I save it using excel. I tried a few other excel extension types: .csv, .xlsx, .xls, .xml (XML Spreadsheet 2003) In all cases, if the file was opened using Excel, and then saved using Excel, visual studio removed it for each and every extension. If I use notepad (E.G, on the .csv file), and saved, visual studio did not remove the file, I.E, it works as I would have expected. Also, I don't actually have to edit it using visual studio... it just has to have the solution open (I.E, running as a minimized window -- launch excel using a windows explorer.)
I suspect the reason has more to do with some kind of excel file locking sequence, than anything to do with templates and visual studio settings, given that it works fine with notepad, but breaks down when using Excel. I spent a little more time, created a fresh machine, installed Office 2010 (V15.0.6112.5000 32-bit), and installed Visual Studio 2010 Ultimate with SP1 (V10.0.40219.1 SP1Rel). The problem is reproduced exactly as I note above... it seems that unless visual studio 2010 Ultimate shipped with corrupted templates and/or settings, I cannot see how settings or templates can be the reason you are unable to reproduce it...
NOTE: I did notice a wierd behavior in that visual studio wanted to immediately open the file in excel the moment I added it as a solution item. This is very wierd behavior... I did not ask to open it, I asked to add it to the solution. It seems unlikely this would be related, but I thought I'd mention it anyway.
Do you have any other suggestions? I do think that perhaps creating the dummy project may ultimately give us the solution we need, and I'm investigating that. In any case, thank you very much for your help and any further information you might be able to suggest.
--
T.
T.Tobler
- 已编辑 T.Tobler 2012年3月6日 14:46
-
2012年3月7日 9:16版主
Hi T.Tobler,
I reproduced you issue now with my college’s help.
The key point to your steps is: when you are editing the XLS file, if you minimize VS, the XLS file will be removed from solution folder.
So please report it to the developers via MS Connect, here:
http://connect.microsoft.com/VisualStudio
Then our Product Group will have a look at this issue.
As for now, the excel file becomes part of solution, thus, the solution file has record. I think you will need to put the solution file under source control to mitigate the impact.
Thanks for understanding.
Best regards,
Barry Wang [MSFT]
MSDN Community Support | Feedback to us
-
2012年3月7日 9:31版主
Hi T.Tobler,
I will report this to PG instead of you. You do not need to report this. I will show you the link later.
This is the link:
Regards,
Barry Wang [MSFT]
MSDN Community Support | Feedback to us
- 已编辑 Barry WangMicrosoft Contingent Staff, Moderator 2012年3月7日 10:12 Add link
-
2012年3月7日 12:58
Thank you Barry.
I've added a watch to the connect issue you created above. Thank you.
Additional information -- As I was trying the workaround of adding the excel file to a project instead of as a solution item, I found that simply adding the excel file to a project prevents the problem. Once it was added as a project file/item, it appears visual studio no longer removed the file from solution items when it was saved from excel. Specifically, here are the steps I followed:
1. Add an empty C# project to the solution - placed in the root folder of all solution files (all projects, application data, build scripts, excel data, etc.).
- I had to manually create the project, then move it to the root folder. Our production file structure has the visual studio solution one folder down from the 'file repository' of all build inputs. Visual studio warned about source control on this project, but I believe it is in a place that is valid for our TFS source control mappings, which we typically map from this same root folder.
2. Edit build configuration on the solution - turn off build for the new project on all build configurations.
3. Add the excel file as a solution item (as before).
4. In the empty project added above, show all folders, and navigate to the folder that contains the excel files, then add it to that project.
- This apparentally automatically adds all files in that folder, including the excel files that were linked as solution items.
5. Edit the excel file by double clicking from the visual studio solution explorer
- as a solution item, save it from excel ==> Works as expected (whether VS is minimized or not)
- as a project file item, save it from excel ==> Works as expected (whether VS is minimized or not)
In summary, it appears one workaround for this issue is to simply add the excel file to one of the projects. In my case, no project was at an appropriate folder level, so the solution I took was to create a new specialized folder just for this purpose (Project name: FileRepository, located one directory above the solution file.. visual studio warned, but again, I believe we can manage this using appropriate source control mappings. Alternatively, we could have moved the excel file locations, but this would have required greater changes to our build scripts, which expect the excel files in a known location.)
This is a viable work around for us. Thanks!
T.Tobler
- 已编辑 T.Tobler 2012年3月7日 13:01
- 已标记为答案 Barry WangMicrosoft Contingent Staff, Moderator 2012年3月8日 9:16

