private void CheckAndLoadEDMPackage(IVsSolution solution)
 {
     if (!IsEDMPackageLoaded())
     {
         // if there is at least one EDMX file in the solution, load the EDM package
         Debug.Assert(solution != null, "Unexpected null value of project");
         if (solution != null)
         {
             foreach (var project in BootstrapUtils.GetProjectsInSolution(solution))
             {
                 var shouldLoadEDMPackage = ShouldLoadEDMPackage(project);
                 if (shouldLoadEDMPackage)
                 {
                     try
                     {
                         LoadEDMPackage();
                         return;
                     }
                     catch (Exception loadPackageException)
                     {
                         Debug.Assert(false, "Caught exception while trying to load EDM package: " + loadPackageException.Message);
                     }
                 }
             }
         }
     }
 }
        private static bool ShouldLoadEDMPackage(IVsHierarchy project)
        {
            var shouldLoadEDMPackage = false;

            try
            {
                if (BootstrapUtils.IsEDMSupportedInProject(project))
                {
                    // Check if project is a website project. If yes, search for edmx files under the app_code folder.
                    // Note that website project doesn't have project file and to exclude files from project you append ".exclude" in file name.
                    var dteProject = BootstrapUtils.GetProject(project);
                    if (dteProject != null &&
                        BootstrapUtils.IsWebProject(dteProject))
                    {
                        var projectFullPathProperty = dteProject.Properties.Item("FullPath");
                        var projectFullPath         = projectFullPathProperty.Value as string;

                        Debug.Assert(String.IsNullOrWhiteSpace(projectFullPath) == false, "Unable to get project full path");
                        if (String.IsNullOrWhiteSpace(projectFullPath) == false)
                        {
                            // App_Code is a special folder that will not be localized should always be under root folder.
                            var appCodePath = Path.Combine(projectFullPath, "App_Code");

                            if (Directory.Exists(appCodePath))
                            {
                                // Directory.GetFiles could potentially be an expensive operation.
                                // If the performance is not acceptable, we should look into calling Win32 API to search for files.
                                shouldLoadEDMPackage =
                                    Directory.GetFiles(appCodePath, "*" + ExtensionEdmx, SearchOption.AllDirectories).Any();
                            }
                        }
                    }
                    else
                    {
                        var fileFinder = new VSFileFinder(ExtensionEdmx);
                        shouldLoadEDMPackage = fileFinder.ExistInProject(project);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("Caught exception in BootstrapPackage's ShouldLoadEDMPackage method. Message: " + ex.Message);
                // We want to continue loading the package if the exception is not critical.
                // Do not do Debug.Assert here because it could cause a lot of DDBasic failures in CHK build.
                if (VSErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }
            }
            return(shouldLoadEDMPackage);
        }