VSX application : CSVSPackageMonitorFileChange Project Overview


Visual Studio provides SVsFileChangeEx service enables arbitrary components
to register to be notified when a file is modified outside of the Environment.

This service is useful when you are performing some operation which will be
interupted by file changes from outside environment.

The service is similar with FileSystemWatcher Class.

To use this sample, follow the steps as below:

1. Start experimental VS instance
2. The package will be autoloaded automatically when there is no any solution
3. The demo monitors user's desktop directory, so please do file or directory
changes in desktop.
4. Visual Studio will popup window whenever a change is made.


VS 2008 SDK must be installed on the machine. You can download it from:

Otherwise the project may not be opened by Visual Studio.

If you run this project on a x64 OS, please also config the Debug tab of the project
Setting. Set the "Start external program" to
C:\Program Files(x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe

NOTE: The Package Load Failure Dialog occurs because there is no PLK(Package Load Key)
     Specified in this package. To obtain a PLK, please to go to WebSite:
     More info

In order to implement this sample, following are the core steps:
(For detailed informaiton, please view sample code)

1. Create package class and specify AutoLoad attribute:
adfc4e64-0397-11d1-9f4e-00a0c911004f represents context that there is
no solution is loaded.

2. In the package's initializate method, add following code:

IVsFileChangeEx fileChangeService =
   GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
monitor = new CSVSMonitorFileChange();
uint cookie;

// Enables a client to receive notifications of changes to a directory.

   // String form of the moniker identifier of
   // the directory in the project system.

   // If true, then events should also be fired
   // for changes to sub directories. If false,
   // then events should not be fired for changes
   // to sub directories.

   // IVsFileChangeEvents Interface on the object
   // requesting notification of file change events.

   // Unique identifier for the file that is
   // associated with the event sink.
   out cookie

3. Implements CSVSMonitorFileChange class which inherited from IVsFileChangeEvents
Implements DirectoryChanged and FilesChanged methods to popup message box
when a change is monitored.


How to get notifications in editor when the file is modified outside of the editor?

IVsFileChangeEvents Interface

SVsFileChangeEx Interface

FileSystemWatcher Class