コード例 #1
0
        void EnsureNoProjectDesignersAreOpen()
        {
            var notified = UserMessageService == null;

            // TODO: Remove this function when NuPattern implements a workaround.
            // The workaround is to close all the project designers, which can cause exceptions in NuPattern's t4 unfold logic.
            // Related NuPattern issue: https://github.com/NuPattern/NuPattern/issues/2
            foreach (var window in Dte.Windows.OfType <Window>().Where(w => w.Type == vsWindowType.vsWindowTypeDocument))
            {
                try
                {
                    // just so this expression compiles
                    var ignore = window.ProjectItem;
                }
                catch (InvalidCastException)
                {
                    if (!notified)
                    {
                        notified = true;

                        UserMessageService.ShowInformation("ServiceMatrix has detected that some Project Designers are open. These designers will now be closed in order to proceed with code generation.");
                    }

                    window.Close();
                }
            }
        }