コード例 #1
0
        public static IProject LoadProject(IMSBuildEngineProvider provider, string location, string title, string projectTypeGuid)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            if (projectTypeGuid == null)
            {
                throw new ArgumentNullException("projectTypeGuid");
            }

            IProject newProject;

            if (!File.Exists(location))
            {
                newProject          = new MissingProject(location, title);
                newProject.TypeGuid = projectTypeGuid;
            }
            else
            {
                ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location);
                if (binding != null)
                {
                    try {
                        location = Path.GetFullPath(location);
                    } catch (Exception) {}
                    try {
                        newProject = binding.LoadProject(provider, location, title);
                    } catch (XmlException ex) {
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                    } catch (Microsoft.Build.BuildEngine.InvalidProjectFileException ex) {
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                    } catch (UnauthorizedAccessException ex) {
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                    }
                }
                else
                {
                    newProject          = new UnknownProject(location, title);
                    newProject.TypeGuid = projectTypeGuid;
                }
            }
            return(newProject);
        }
コード例 #2
0
        public static IProject LoadProject(IMSBuildEngineProvider provider, string location, string title, string projectTypeGuid, IProgressMonitor progressMonitor)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            if (projectTypeGuid == null)
            {
                throw new ArgumentNullException("projectTypeGuid");
            }

            if (progressMonitor != null)
            {
                progressMonitor.BeginTask("Loading " + title, 0, false);
            }

            IProject newProject;

            if (!File.Exists(location))
            {
                newProject          = new MissingProject(location, title);
                newProject.TypeGuid = projectTypeGuid;
            }
            else
            {
                ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location);
                if (binding != null)
                {
                    location = FileUtility.NormalizePath(location);
                    try {
                        newProject = binding.LoadProject(provider, location, title);
                    } catch (ProjectLoadException ex) {
                        LoggingService.Warn("Project load error", ex);
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = true;
                        }
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = false;
                        }
                    } catch (UnauthorizedAccessException ex) {
                        LoggingService.Warn("Project load error", ex);
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = true;
                        }
                        newProject          = new UnknownProject(location, title, ex.Message, true);
                        newProject.TypeGuid = projectTypeGuid;
                        if (progressMonitor != null)
                        {
                            progressMonitor.ShowingDialog = false;
                        }
                    }
                }
                else
                {
                    string ext = Path.GetExtension(location);
                    if (".proj".Equals(ext, StringComparison.OrdinalIgnoreCase) ||
                        ".build".Equals(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        newProject          = new MSBuildFileProject(location, title);
                        newProject.TypeGuid = projectTypeGuid;
                    }
                    else
                    {
                        newProject          = new UnknownProject(location, title);
                        newProject.TypeGuid = projectTypeGuid;
                    }
                }
            }
            return(newProject);
        }