|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
![]() ![]() Introduction
The absence of tools in Visual Studio that can help developers to create Vista gadgets is strange and disappointing, in my opinion. Maybe, it's a temporary state, but now, I want to show you some tools that can help you to develop Vista gadgets using only Visual Studio 2008 IDE. These tools include Visual Studio template for creating Vista gadgets and Visual Studio add-in for creating a .gadget file from a project and run a gadget installation. BackgroundBy now, if we want to create a Vista gadget, we should following next steps:
All this action is executed from
Windows Explorer. If you will create gadget for company which policy
will require sign all assemblies and executed files that will have
created in it you also will be engaged into using cabarc.exe and
signtool.exe for signing your gadget. It’s a really boring task to
create a signed gadget without any automation. So, how we can automate all these steps using Visual Studio IDE?
The answer can be the add-in that was created for helping in development Vista gadget. With this add-in you can easily build signed and unsigned gadget using onle one click on menu item or toolbar button or using shortcuts(Ctrl+R, Ctrl + R this combination can be changed). So, how to install it? For this issue I've prepared some installation pack. Below I describe how to install all these stuff. InstallationIn installation pack I have prepared:
So, when you are already have installed addin and some templates you should define some important options for your future gadget development. For this issue you should open addin settings window and define some parameters. Choose from menu Gadget -> Open gadget properties window or choose corresponding appropriate button from toolbar.
Then you should see the next window.
In this window you should define:
3.1 Mark checkbox “Is will build signed gadget” 3.2 Define core signtool.exe utility path for this action. You can find more about this utility here - http://msdn.microsoft.com/en-us/library/8s9b9yaz.aspx 3.3 If you have ready to use .pfx file (personal information exchange file) define path to it. 3.4 If you haven’t .pfx file but you have .pvk and one from .spc or .cer files you can make new .pfx file using pvk2pfk.exe utility. You can find more about this utility here - http://msdn.microsoft.com/en-us/library/aa906332.aspx 3.5 Define also password for your .pfx file. After you have completed entering all needed information click button "Save" for saving these options. Congratulations! Now you are ready to use addin from your Visual Studio 2008 IDE. Using Add-In And Templates When you already complete installation process you are ready for
creating your own gadget with Visual Studio IDE. In this case you
should open menu item: File -> Open -> Web site.
When you click on this template Visual Studio is opened new web site which structure would resemble real gadget project structure as you can see on the picture.
Here you can find only one foreign element - it's a web.config file.
But if you are going to build gadget using RunVistaGadgetAddIn it is
not an obstacle, because addin wouldn't include this file to output
.gadget file.
By now after clicking on "Run gadget" button you are always should see
this window that suggest you install gadget on Windows sidebar. But I'm
descovered some problem with this scenario when gadget have used
settings option in its code. You can have had a problem with installing
gadget on sidebar in this case after first installation. Really it's
not a problem, just you shoul twice repeate installation process. I'm
personally trying to find out the reason for such behavior, but only
reveal that Windows Sidebar has held some gadget files opened and
hadn't clear resources after closing gadget on the sidebar. So, if you
find out how to resolve this issue let me know, please! Development
In this topic I'm trying to explain you how this add-in works. How to
work the main part of add-in. How you can create you own template. And
at the end of this topic I discribe you how you can prepare
installation for Visual Studio add-in and templates. if (isHaveLoadedProject())
{
SaveAllChangedFiles();
CreateGadget();
if (isBuildSignGadget())
{
SignGadget();
}
RunGadget();
}
First of all I want to remind that all action in addin are commands.
Exec method is called when some command is invoked. Exec method is
common handler for all commands. So, mentioned above piece of code
executed from Exec method too, but only for particular command (in this
case RunGadget command). For running gadget we should asking on
question - is already some project loaded in IDE (it would be better if
it will be some gadget project as well). Then we save all changed files
in this project, afterwards addin create gadget file. Then it check if
we should sign gadget. If we should we will sign gadget. And at the end
addin trying to run gadget installation.
For this purpose we can call cmd command like: "C:\Program Files\Windows Sidebar\sidebar.exe /showgadgets". More about sidebar command looking for on this post. From C# code we can use mentioned above ApplicationRunner base class for this purpose. So, we need create new class that should inherits from ApplicationRunner class and override two methods. In this addin I've created class SidebarSettingsRunner. The code for this class you can see below: class SidebarControlConsoleRunner: ApplicationRunner
{
public SidebarControlConsoleRunner(DTE2 applicationObject)
: base(applicationObject, false){ }
public SidebarControlConsoleRunner(DTE2 applicationObject, bool isRunAsWinApp)
: base(applicationObject, isRunAsWinApp){ }
public override string GetAppArguments()
{
String GadgetArgs = " /showgadgets";
return GadgetArgs;
}
public override string GetOutputAndRunApplication()
{
base.CalledApplicationPath = "c:\\" +
Environment.SpecialFolder.ProgramFiles + Path.DirectorySeparatorChar +
"Windows Sidebar\\sidebar.exe";
return base.GetOutputAndRunApplication();
}
} As you can see here for GetAppArguments method we are define that argument would be " /cpl". For GetOutputAndRunApplication method we are define application path for sidebar.exe file and return output string after the application have been run. Furthermore we can use this class like in this code snippet: SidebarControlConsoleRunner sccr = new SidebarControlConsoleRunner(applicationObject, true);
String AppOutput = sccr.GetOutputAndRunApplication();
where
applicationObject - is a global for this add in object which you can
define on OnConnection event handler for current add in instance. public void OnStartupComplete(ref Array custom)
{
Command OpenVistaSidebarControlConsoleCommand = null;
CommandBar menuCommandBar;
CommandBar GadgetTemporaryToolbar;
CommandBars commandBars;
CommandBarButton OpenVistaSidebarControlConsoleCommandBarButton;
CommandBarControl GadgetToolsCommandBarControl;
CommandBarPopup GadgetTemporaryCommandBarPopup;
try
{
OpenVistaSidebarControlConsoleCommand =
applicationObject.Commands.Item(addInInstance.ProgID + "." +
OPEN_VISTA_SIDEBAR_CONTROL_CONSOLE_COMMAND_NAME, 3);
}
catch
{
}
object[] contextGUIDS3 = new object[] { };
// Add the command if it does not exist
if (OpenVistaSidebarControlConsoleCommand == null)
{
OpenVistaSidebarControlConsoleCommand =
applicationObject.Commands.AddNamedCommand(addInInstance,
OPEN_VISTA_SIDEBAR_CONTROL_CONSOLE_COMMAND_NAME, "Open Vista Sidebar
Control Console", "Open Vista Sidebar Control Console", true, 548, ref
contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported +
(int)vsCommandStatus.vsCommandStatusEnabled);
}
commandBars = (CommandBars)applicationObject.CommandBars;
menuCommandBar = commandBars["MenuBar"];
// Add a new toolbar with a button on it
GadgetTemporaryToolbar =
commandBars.Add("VistaGadgetDevelopmentToolbar",
MsoBarPosition.msoBarTop, System.Type.Missing, true);
// Change the button style, which must be done casting the control to a button
OpenVistaSidebarControlConsoleCommandBarButton =
(CommandBarButton)OpenVistaSidebarControlConsoleCommand.AddControl(GadgetTemporaryToolbar,
GadgetTemporaryToolbar.Controls.Count + 1);
OpenVistaSidebarControlConsoleCommandBarButton.Style = MsoButtonStyle.msoButtonIcon;
// Add a new command bar popup with a button on it
GadgetTemporaryCommandBarPopup =
(CommandBarPopup)menuCommandBar.Controls.Add(MsoControlType.msoControlPopup,
System.Type.Missing, System.Type.Missing, position, true);
GadgetTemporaryCommandBarPopup.CommandBar.Name = "VistaGadgetDevelopmentCommandBarPopup";
GadgetTemporaryCommandBarPopup.Caption = "Gadget";
OpenVistaSidebarControlConsoleCommand.AddControl(GadgetTemporaryCommandBarPopup.CommandBar,
GadgetTemporaryCommandBarPopup.Controls.Count + 1);
}Some cool features of Visual Studio IDE can be used for saving time for developers. On of them is creating and using Visual Studio templates for projects and items. You can prepare your own template for some project and open entire project in a few minutes without writing any code string. The real benefit for template is simplisity for creating your own instance one. The most easy way is accepted for Team Edition owners. This guys should only prepare templated project and choose menu item File -> Export Template... The rest can create template using methods that was described in the good article by Ron Petrusha "Creating Visual Studio Project Templates". Another intersting subject in Add in development is a deployment. You can create and share items for use in Visual Studio. There are exist add-in item among other. With this item you can easier deliver add-in to other developers. For use it with Visual Studio you can package the item in a .vsi file, which can be installed by using the Visual Studio Content Installer. The Visual Studio Content Installer automatically copies the add-in items to the correct directories on a developer's computer so that the items appear in the correct dialog boxes in Visual Studio. To use the Visual Studio Content Installer to install your community components, you must create a .vscontent file for the component. After you create the .vscontent file, you compress the component files and the .vscontent file into a .zip file and change the file name extension from .zip to .vsi. More about creating package for add-in and creating .vscontent file you can find in this article. Also I want to denote a beautiful book about creating Visual Studio add-in which has always been a source of inspiration for me when I thinking about update for this article. There is Keyvan Nayyery "Professional Visual Studio Extensibility" book. I would be very much obliged to him for such interesting and useful for me book.ConclusionIn this article, I show you how to create a Visual Studio Vista Gadget project template and use it from the Visual Studio IDE. Also, I show you how to install and use the RunVistaGadget Visual Studio add-in for running a Vista gadget from Visual Studio IDE. Why is it comfortable to use the Visual Studio IDE for creating a Vista gadget?
HistoryHere is first version of this article - RunVistaGadget.aspx
|
||||||||||||||||||||||