Максим Павловский twitter: @paulousky .
-
Upload
owen-nelson -
Category
Documents
-
view
226 -
download
0
Transcript of Максим Павловский twitter: @paulousky .
Разработка расширений для Visual Studio 2010
Максим Павловский
twitter: @paulouskyhttp://www.maxpaulousky.com
Необходимые инструменты
Visual Studio 2010 Professional или лучшеVisual Studio 2010 SDK
Создание, отладка и публикация расширений
Разработка в Visual Studio 2010;Из чего состоит проект расширения Visual Studio Package;Запуск и отладка в Visual Studio 2010 experimental instance;Публикация в Visual Studio Gallery.
Visual Studio Gallery
Создание расширения для Visual Studio
Демонстрация
Основа расширения
Реализация Microsoft.VisualStudio.Shell.Package;Использование IServiceProvider для доступа к различным составляющим Visual Studio
Сервисы Visual Studio
IVsSolution;IVsStatusbarIVsOutputWindowPane;IVsWebBrowsingService;IVsToolWindowToolbarHost;etc.
Примеры использования сервисов
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;
}
Примеры использования сервисов
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));
Примеры использования сервисов
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”);
Обработка проектов
Получение типа (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 (CodeElement elemenentN in (element as CodeNamespace).Members){
if (elemenentN.Kind == vsCMElement.vsCMElementClass)
return true;}
}}
}
Изменение reference assemblies проектаproject.References.Add(<path_to_assembly>);
project.References.AddProject(projectReference.SourceProject);
Алгоритм минимизации XAP файлов
Xaps Minifier. Уменьшение размера Silverilight приложений
Демонстрация
Полезные ссылки
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
Спасибо! Ваши отзывы будут очень полезны