Download - Разработка расширений для Visual Studio 2010
![Page 1: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/1.jpg)
Разработка расширений для Visual Studio 2010 Максим Павловский
twitter: @paulouskyhttp://www.maxpaulousky.com
![Page 2: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/2.jpg)
Необходимые инструменты
Visual Studio 2010 Professional или лучшеVisual Studio 2010 SDK
![Page 3: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/3.jpg)
Создание, отладка и публикация расширений
Разработка в Visual Studio 2010;Из чего состоит проект расширения Visual Studio Package;Запуск и отладка в Visual Studio 2010 experimental instance;Публикация в Visual Studio Gallery.
![Page 4: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/4.jpg)
Visual Studio Gallery
![Page 5: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/5.jpg)
Создание расширения для Visual Studio
Демонстрация
![Page 6: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/6.jpg)
Основа расширенияРеализация Microsoft.VisualStudio.Shell.Package;Использование IServiceProvider для доступа к различным составляющим Visual Studio
![Page 7: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/7.jpg)
Сервисы Visual StudioIVsSolution;IVsStatusbarIVsOutputWindowPane;IVsWebBrowsingService;IVsToolWindowToolbarHost;etc.
![Page 8: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/8.jpg)
Примеры использования сервисов
private IEnumerable<IVsHierarchy> GetProjects(__VSENUMPROJFLAGS flags, Guid projectGuid){
IEnumHierarchies enumHier;
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;
}
![Page 9: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/9.jpg)
Примеры использования сервисов
Bitmap bitmap = …IntPtr bitmapHdc = bitmap.GetHbitmap();Object bitmapObjHdc = (Object)bitmapHdc;
//Start animationint isTurnedOn = 1statusbar.Animation(isTurnedOn, ref bitmapObjHdc);
//Set progress text and progress bar valueint InProgress = 1;int currentValue = 50;int Total = 100;string message = “Processing”;statusbar.Progress(ref statusBarId, InProgress, message, currentValue, total));
![Page 10: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/10.jpg)
Примеры использования сервисов
IVsOutputWindow output = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
//Guid of your outputwindowGuid outputPaneGuid = new Guid(…);output.CreatePane(ref outputPaneGuid, “Test", 1, 1);IVsOutputWindowPane pane;output.GetPane(ref outputPaneGuid, out pane);pane.Activate();pane.OutputString(“Output message”);
![Page 11: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/11.jpg)
Обработка проектовПолучение типа (asp.net, библиотека, windows service etc), языка (c#, VB) проекта;Получение свойств проекта;Получение элементов проекта (файлы, папки, классы, простанства имён и т.д.);Обработка reference assemblies проекта.
![Page 12: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/12.jpg)
Получение типа и языка проекта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();}
![Page 13: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/13.jpg)
Поиск всех классов проекта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 (CodeElement elemenentN in (element as CodeNamespace).Members){
if (elemenentN.Kind == vsCMElement.vsCMElementClass)
return true;}
}}
}
![Page 14: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/14.jpg)
Изменение reference assemblies проектаproject.References.Add(<path_to_assembly>);
project.References.AddProject(projectReference.SourceProject);
![Page 15: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/15.jpg)
Алгоритм минимизации XAP файлов
![Page 16: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/16.jpg)
Xaps Minifier. Уменьшение размера Silverilight приложений
Демонстрация
![Page 17: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/17.jpg)
Полезные ссылкиXaps Minifier http://bit.ly/XapsMin;Visual Studio Gallery; http://visualstudiogallery.msdn.microsoft.com/Visual Studio SDK Reference http://msdn.microsoft.com/en-us/library/bb166217.aspxVS extensibility resources http://www.mztools.com/resources_vsnet_addins.aspx
![Page 18: Разработка расширений для Visual Studio 2010](https://reader034.vdocument.in/reader034/viewer/2022051420/56815f40550346895dce18e0/html5/thumbnails/18.jpg)
Спасибо! Ваши отзывы будут очень полезны