Run external tool before save in Visual Studio

Sachelis 21 Reputation points
2021-02-07T15:17:22.62+00:00

I have an External Tool in Visual Studio (not Code) that I can run from the Tools menu. Is it possible to have this tool run automatically before a file is saved (on a per-project basis)?

Thanks!

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,693 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sergey Vlasov 266 Reputation points
    2021-02-08T07:09:57.403+00:00

    You can run a tool after the file is saved like this: https://vlasovstudio.com/visual-commander/extensions.html#OnDocumentSaved

    There is no similar event before the file is saved and the tool wouldn't be able to access the file content as it is not yet saved.

    You may also look at single-file generators that can transform a single input file into a single output file whenever the file is saved: https://learn.microsoft.com/en-us/visualstudio/extensibility/internals/custom-tools?view=vs-2019

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-02-08T05:12:36.217+00:00

    Hi Sachelis,

    Currently, VS IDE does not support extending Save commands and automatically running external tools.

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments