180 likes | 513 Views
Максим Павловский twitter : @ paulousky http://www.maxpaulousky.com. Разработка расширений для Visual Studio 2010. Необходимые инструменты. Visual Studio 2010 Professional или лучше Visual Studio 2010 SDK. Создание , отладка и публикация расширений. Разработка в Visual Studio 2010 ;
E N D
Максим Павловский twitter: @paulousky http://www.maxpaulousky.com Разработка расширений для Visual Studio 2010
Необходимые инструменты • Visual Studio 2010 Professional или лучше • Visual Studio 2010 SDK
Создание, отладка и публикация расширений • Разработка в Visual Studio 2010; • Из чего состоит проект расширения Visual Studio Package; • Запуск и отладка в Visual Studio 2010experimental instance; • Публикация в Visual Studio Gallery.
Создание расширения для Visual Studio Демонстрация
Основа расширения • Реализация Microsoft.VisualStudio.Shell.Package; • Использование IServiceProvider для доступа к различным составляющим Visual Studio
Сервисы Visual Studio • IVsSolution; • IVsStatusbar • IVsOutputWindowPane; • IVsWebBrowsingService; • IVsToolWindowToolbarHost; • etc.
Примеры использования сервисов • private IEnumerable<IVsHierarchy> GetProjects(__VSENUMPROJFLAGS flags, GuidprojectGuid){IEnumHierarchiesenumHier;solution.GetProjectEnum((uint)flags, ref projectGuid, out enumHier);uint fetched = 1;IVsHierarchy[] hier = new IVsHierarchy[10];while (fetched > 0){ErrorHandler.ThrowOnFailure( enumHier.Next(10, hier, out fetched));for (int n = 0; n < fetched; ++n)yield return hier[n];}yield break;}
Примеры использования сервисов • Bitmap bitmap = … • IntPtrbitmapHdc = bitmap.GetHbitmap(); • Object bitmapObjHdc = (Object)bitmapHdc; • //Start animation • intisTurnedOn = 1 • statusbar.Animation(isTurnedOn, ref bitmapObjHdc); • //Set progress text and progress bar value • intInProgress = 1; • intcurrentValue = 50; • int Total = 100; • string message = “Processing”;statusbar.Progress(ref statusBarId, InProgress, message, currentValue, total));
Примеры использования сервисов • IVsOutputWindow output = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; • //Guid of your outputwindowGuidoutputPaneGuid = new Guid(…);output.CreatePane(ref outputPaneGuid, “Test", 1, 1); • IVsOutputWindowPane pane;output.GetPane(ref outputPaneGuid, out pane);pane.Activate(); • pane.OutputString(“Output message”);
Обработка проектов • Получение типа (asp.net, библиотека, windows service etc), языка (c#, VB) проекта; • Получениесвойств проекта; • Получение элементов проекта (файлы, папки, классы, простанства имён и т.д.); • Обработка reference assemblies проекта.
Получение типа и языка проекта • private IEnumerable<string> GetProjectTypeGuids(Project project){string projectTypeGuids = string.Empty;IVsHierarchy hierarchy = GetVsHierarchy(project);if (hierarchy as IVsAggregatableProject != null)(hierarchy as IVsAggregatableProject).GetAggregateProjectTypeGuids(out projectTypeGuids);if (string.IsNullOrWhiteSpace(projectTypeGuids))return Enumerable.Empty<string>();return projectTypeGuids.Split(';').ToList();}
Поиск всех классов проекта • ProjectItems items = project.ProjectItems;foreach (ProjectItem item in items){if (item.FileCodeModel == null)continue;foreach (CodeElement element in item.FileCodeModel.CodeElements){if (element.Kind == vsCMElement.vsCMElementNamespace){foreach (CodeElementelemenentNin (element asCodeNamespace).Members){if (elemenentN.Kind == • vsCMElement.vsCMElementClass)return true; } } }}
Изменение reference assemblies проекта • project.References.Add(<path_to_assembly>); • project.References.AddProject(projectReference.SourceProject);
XapsMinifier. Уменьшение размера Silverilightприложений Демонстрация
Полезные ссылки • XapsMinifierhttp://bit.ly/XapsMin; • Visual Studio Gallery; http://visualstudiogallery.msdn.microsoft.com/ • Visual Studio SDK Reference http://msdn.microsoft.com/en-us/library/bb166217.aspx • VS extensibility resources http://www.mztools.com/resources_vsnet_addins.aspx
Спасибо! Ваши отзывы будут очень полезны