protected override void Initialize()
        {
            base.Initialize();

            // for command line builds we only have a minimal set of functionality to only support building
            if (IsBuildingFromCommandLine)
            {
                InitializeForCommandLineBuilds();
            }
            else
            {
                // HACK HACK -- find a better place to do this.
                EFModelErrorTaskNavigator.DslDesignerOnNavigate = DSLDesignerNavigationHelper.NavigateTo;
                // --

                HostContext.Instance.LogUpdateModelWizardErrorAction = ErrorListHelper.LogUpdateModelWizardError;
                PackageManager.Package = this;
                _dispatcher = Dispatcher.CurrentDispatcher;

                // make sure that we can load the XML Editor package
                var vsShell = (IVsShell)GetService(typeof(SVsShell));
                if (vsShell != null)
                {
                    var editorPackageGuid = CommonPackageConstants.xmlEditorPackageGuid;
                    IVsPackage editorPackage;
                    NativeMethods.ThrowOnFailure(vsShell.LoadPackage(ref editorPackageGuid, out editorPackage));
                }

                _documentFrameMgr = new EntityDesignDocumentFrameMgr(PackageManager.Package);
                _modelChangeEventListener = new ModelChangeEventListener();
                _guidsCache = new AggregateProjectTypeGuidCache();
                _modelGenErrorCache = new ModelGenErrorCache();
                _connectionManager = new ConnectionManager();

                AddToolWindow(typeof(MappingDetailsWindow));

                // Register for VS Events
                ErrorListHelper.RegisterForNotifications();

                // Add the handler to show our Explorer. This is for the top-level 'Entity Data Model Browser' command that is added to the
                // 'View' main menu. This is different from the 'Model Browser' command on the designer context menu.
                _viewExplorerCmd = AddCommand(
                    ShowExplorerWindow, ShowExplorerWindow_BeforeQueryStatus, MicrosoftDataEntityDesignCommands.ViewExplorer);

                // Add the handler to show our MappingDesigner. This is for the top-level 'Entity Data Model Mapping Details' command that is added
                // to the 'View' main menu. This is different from the 'Mapping Details' command on the designer context menu.
                _viewMappingCmd = AddCommand(
                    ShowMappingDetailsWindow, ShowMappingDetailsWindow_BeforeQueryStatus, MicrosoftDataEntityDesignCommands.ViewMapping);

                // Subscribe to Project's target framework retargeting
                var projectRetargetingService = GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;
                Debug.Assert(null != projectRetargetingService, "TrackProjectRetargeting service is null");
                _trackProjectRetargetingEventsCookie = 0;
                if (projectRetargetingService != null)
                {
                    projectRetargetingService.AdviseTrackProjectRetargetingEvents(this, out _trackProjectRetargetingEventsCookie);
                }

                // There is no SQL CE support dev12 onward, so removing the references

#if (VS11)
                // Subscribe to the SQL CE and SqlDatabaseFile upgrade services
                var sqlCeUpgradeService = GetGlobalService(typeof(IVsSqlCeUpgradeService)) as IVsSqlCeUpgradeService;
#endif

                var sqlDatabaseFileUpgradeService =
                    GetGlobalService(typeof(IVsSqlDatabaseFileUpgradeService)) as IVsSqlDatabaseFileUpgradeService;

#if (VS12ORNEWER)
                if (sqlDatabaseFileUpgradeService == null)
#else
                if (sqlCeUpgradeService == null
                    || sqlDatabaseFileUpgradeService == null)
#endif
                {
                    // attempt to start IVsSqlCeUpgradeService and IVsSqlDatabaseFileUpgradeService
                    BootstrapVSDesigner();

#if (VS11)
                    if (sqlCeUpgradeService == null)
                    {
                        sqlCeUpgradeService = GetGlobalService(typeof(IVsSqlCeUpgradeService)) as IVsSqlCeUpgradeService;
                    }
#endif

                    if (sqlDatabaseFileUpgradeService == null)
                    {
                        sqlDatabaseFileUpgradeService =
                            GetGlobalService(typeof(IVsSqlDatabaseFileUpgradeService)) as IVsSqlDatabaseFileUpgradeService;
                    }
                }

#if (VS11)
                Debug.Assert(null != sqlCeUpgradeService, "sqlCeUpgradeService service is null");
                if (sqlCeUpgradeService != null)
                {
                    sqlCeUpgradeService.OnUpgradeProject += EdmUtils.SqlCeUpgradeService_OnUpgradeProject;
                }
#endif

                Debug.Assert(null != sqlDatabaseFileUpgradeService, "sqlDatabaseFileUpgradeService service is null");
                if (sqlDatabaseFileUpgradeService != null)
                {
                    sqlDatabaseFileUpgradeService.OnUpgradeProject += EdmUtils.SqlDatabaseFileUpgradeService_OnUpgradeProject;
                }
            }
        }
        protected override void Dispose(bool disposing)
        {
            try
            {
                // HACK HACK -- change when the hack is removed above
                EFModelErrorTaskNavigator.DslDesignerOnNavigate = null;
                // --

                // always dispose and null out items that use VS resources
                _viewExplorerCmd = null;
                _viewMappingCmd = null;

                if (_explorerWindow != null)
                {
                    _explorerWindow.Dispose();
                    _explorerWindow = null;
                }

                if (_mappingDetailsWindow != null)
                {
                    // don't need to call this, the MDF takes care of this one
                    //_mappingDetailsWindow.Dispose();
                    _mappingDetailsWindow = null;
                }

                // remove all errors
                ErrorListHelper.RemoveAll();

                // Unregister for VS Events
                ErrorListHelper.UnregisterForNotifications();

                // dispose of our classes in reverse order than we created them
                if (_connectionManager != null)
                {
                    _connectionManager.Dispose();
                    _connectionManager = null;
                }

                if (_modelChangeEventListener != null)
                {
                    _modelChangeEventListener.Dispose();
                    _modelChangeEventListener = null;
                }

                if (_documentFrameMgr != null)
                {
                    _documentFrameMgr.Dispose();
                    _documentFrameMgr = null;
                }

                _modelManager.Dispose();

#if (VS11)
                // UnSubscribe from the SQL CE upgrade service
                var sqlCeUpgradeService = GetGlobalService(typeof(IVsSqlCeUpgradeService)) as IVsSqlCeUpgradeService;
                if (sqlCeUpgradeService != null)
                {
                    sqlCeUpgradeService.OnUpgradeProject -= EdmUtils.SqlCeUpgradeService_OnUpgradeProject;
                }
#endif
                // UnSubscribe from the SqlDatabaseFile upgrade service
                var sqlDatabaseFileUpgradeService =
                    GetGlobalService(typeof(IVsSqlDatabaseFileUpgradeService)) as IVsSqlDatabaseFileUpgradeService;
                if (sqlDatabaseFileUpgradeService != null)
                {
                    sqlDatabaseFileUpgradeService.OnUpgradeProject -= EdmUtils.SqlDatabaseFileUpgradeService_OnUpgradeProject;
                }

                // clear out any static references
                PackageManager.Package = null;
                Services.ServiceProvider = null;
                _dispatcher = null;
            }
            finally
            {
                base.Dispose(disposing);
            }
        }