How to know if the solution has been modified?

Asked

Viewed 114 times

4

I would like to make a code, which when it is executed, I would know if the solution has been changed and which project has been changed, but I do not know if there is a method to be used. Then I’d like your help.

  • 1

    Are you doing an add-in? Or would it be an application that runs parallel to Visual Studio?

  • An application running parallel to the VS.

1 answer

4


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

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 the notifications:

static void WatcherEvent(object sender, FileSystemEventArgs e)
{
    // alterações nos arquivos ocorreram!
    // verificar o argumento `e` para saber o que ocorreu.
}
  • Thank you very much, it fell like a glove.

  • 1

    Beauty... if you need help with class, tell me that I add more information on how to use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.