Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I AutoSave my Visual Studio 2015 files when it loses focus?

Tags:

I'm working with CSS, HTML, and JavaScript in my classes, and I've recently started working with Visual Studio 2015. In Notepad++, there's an add-on that allowed me to automatically save all my opened documents as soon as it lost focus. This saved me a lot of time, as I go back and forth frequently between the page I'm working on and the coding for it.

I'm hoping there is a similar add-on for Visual Studio 2015, so I can stop forgetting to save before checking my work on its web page! Anyone know of any?

like image 349
Alan Nelson Avatar asked Nov 06 '15 19:11

Alan Nelson


People also ask

How do I recover files in Visual Studio?

You can also specify if you want to restore modified files if Visual Studio shuts down unexpectedly. To access this dialog box, go to Tools > Options > Environment > AutoRecover.

How does Visual Studio save code automatically?

The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay. For more control over Auto Save , open User or Workspace settings and find the associated settings: files.

How do you save a visual File?

From the File menu, choose Save File As, and then click the drop-down button next to the Save button. The Advanced Save Options dialog box is displayed.


1 Answers

You can use the following extension for Visual Commander to auto save files on switching away from Visual Studio:

public class E : VisualCommanderExt.IExtension
{
    public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package)
    {
        DTE = DTE_;
        System.Windows.Application.Current.Deactivated += OnDeactivated;
    }

    public void Close()
    {
        System.Windows.Application.Current.Deactivated -= OnDeactivated;
    }

    private void OnDeactivated(object sender, System.EventArgs e)
    {
        try
        {
            DTE.ExecuteCommand("File.SaveAll");
        }
        catch (System.Exception ex)
        {
        }
    }

    private EnvDTE80.DTE2 DTE;
}
like image 70
Sergey Vlasov Avatar answered Nov 18 '22 13:11

Sergey Vlasov