Check for unsaved changes and ask user to save

南楼画角 提交于 2019-12-11 14:58:08

问题


I'm writing an extension which adds files to projects in the solution.

It makes sense to check first for unsaved changes and if there are any, ask user to save.

How can I achieve this?

Are there any open source VS extensions which do this so I can take a look how it's done?


回答1:


To find out if there are unsaved changes, you can enumerate open documents with DTE.Documents and check each one for the Document.Saved property.




回答2:


You can try to work with project via Microsoft.Build.Evaluation that has corresponding functional.

Extension which adds files to projects in the solution.

After including new files to the project, they must be reevaluated. Pay your attention on Project.IsDirty property:

A project is modified and must be reevaluated when the underlying project source code, including changes to imported files. A project is also modified must be reevaluated if the project tool set changes.


Project.IsDirty | Project.ReevaluateIfNecessary | Project.Save



来源:https://stackoverflow.com/questions/55672375/check-for-unsaved-changes-and-ask-user-to-save

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