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

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;
}

The solution above with

DTE.ExecuteCommand("File.SaveAll");

is too slow in case of 1000+ projects in solution, MSVS UI hangs for several seconds on each losing focus event and extremely consumes CPU, even if there are no unsaved changes.

I've edited OnDeactivated() method, and it works much faster in my cases:

private void OnDeactivated(object sender, System.EventArgs e)
{
    try
    {
        EnvDTE.Documents docs = DTE.Documents;

        for (int i = 1; i <= docs.Count; i++) {
            EnvDTE.Document doc = docs.Item(i);
            if (!doc.Saved) {
                doc.Save();
            }
        }
    }
    catch (System.Exception ex)
    {
    }
}