How do I know if the solution has been modified?

4

I would like to make a code, which when executed, would know if the solution was changed and which project has changed, but I do not know if there is a method to take as a basis. Then I would like your help.

    
asked by anonymous 01.04.2015 / 22:08

1 answer

4

There is a .Net class that is used to monitor changes to the file system:

With it you can make the following code to be notified whenever a file changes:

// Criar uma instância do FileSystemWatcher e configurá-la.
var watcher = new FileSystemWatcher(
    "C:\MinhaSolucao\", // caminho raiz da solução a ser monitorada
    "*.csproj"            // vamos monitorar os arquivos 'csproj' dentro do caminho acima
    );

// Adicionando os eventos para notificação de alterações.
watcher.Changed += new FileSystemEventHandler(WatcherEvent);
watcher.Created += new FileSystemEventHandler(WatcherEvent);
watcher.Deleted += new FileSystemEventHandler(WatcherEvent);
watcher.Renamed += new RenamedEventHandler(WatcherEvent);

// Iniciar o monitoramento.
watcher.EnableRaisingEvents = true;

Code receiving notifications:

static void WatcherEvent(object sender, FileSystemEventArgs e)
{
    // alterações nos arquivos ocorreram!
    // verificar o argumento 'e' para saber o que ocorreu.
}
    
01.04.2015 / 22:29