Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] - نسخه متنی

Brian Johnson

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










Sharing Macros with Others


If you want to share the macros that you've created, you have a number of choices to make. Do you want to share the source? Do you want to share the whole project or just part of it? The answers to these questions will determine how to best share your work. Let's take a look at the different ways that you can share your macro functionality with others.


Exporting Modules and Projects


The easiest way to share your macros with other developers is to simply cut and paste your source code into e-mail messages and Usenet postings. This approach works well if the methods you're sharing are fairly short and if they don't span multiple modules. If they do span multiple modules, you'll probably want to export the modules you want to share or simply pass on the whole project.

To export a macro module in Visual Studio .NET, you must open the Macros IDE and select the module you want to export from the Project Explorer window. Pressing Ctrl+E will invoke the File.SaveSelectedItemsAs command, which brings up the Export File dialog box. This command is listed on the File menu as Export.

The Export File dialog box lets you save the module as a .vb file that you can easily import into another project using the File.AddExisitingItem command (Shift+Alt+A). Don't forget to include the code from the EnvironmentEvents module if your macros rely on some sort of event functionality.

If your macros are very complicated, you might want to share an entire macro project. You can do this in a couple of ways. You can copy the .vsmacros file for the project and pass it along, or you can save your macro project as a text-based project and share those files.

To make a macros project text-based, you change the StorageFormat property in the Visual Studio .NET IDE for the project that you want to change. Select the project in Macro Explorer and then change the StorageFormat property in the Properties window from Binary (.vsmacros) to Text (UNICODE). This change will create a number of files in the macro project's folder that looks much like a regular Visual Studio .NET project folder. In Figure 4-9, you can see the folder for the Samples project after it has been converted to Text format.


Figure 4-9. A macro project that has been stored in Text format



The advantage of passing along a text-based project is that it allows other programmers to look at the source files in your project before loading them into their IDE.

There's always a security risk in opening unknown macro projects in any application. Be sure you know where any binaries you open came from. At the very least, check the EnvironmentEvents.vb module to make sure it doesn't include any unexpected code.

Also keep in mind that shipping a binary macro project does nothing to safeguard your source code. To do that, you're better off adding your functionality to an assembly that gets called from a macro, as we demonstrated earlier. An even better solution, where appropriate, is to turn your macro project into an add-in.


Turning Macros into Add-ins


Visual Studio .NET ships with a macro in the Samples project that lets you turn a macro project into a Visual Studio .NET add-in, complete with an installer. The macros in the MakeAddin module take a macro and turn it into an add-in project that you can compile and install into your environment. Macros that have been turned into add-ins can be shipped as binaries that are installed on a user's machine. Keep in mind, though, that you really should test the add-ins that you create in this way to make sure they do what you expect.

For this example, we'll take the AutoHideToggle macro that we created in Chapter 1 and turn it into an add-in using the MakeAddin macros. To get started, copy the macro you want to turn into an add-in into a new macro project. You can give the project the same name as the method if you want. Just be sure to build the new project to test it before you use it.

Next, you create a new add-in project in Visual Studio .NET by pressing Ctrl+Shift+N to open the New Project dialog box. Expand the Other Projects folder and then open the Extensibility Projects folder to get to the Visual Studio .NET Add-in project template, as shown in Figure 4-10.


Figure 4-10. Creating a new add-in project



Give your new add-in an appropriate name, and then go through the wizard to create a Visual Basic .NET add-in project that installs a menu command in the IDE.

After your new add-in project is complete, press Ctrl+Alt+A to bring up the Command Window and then type Macros.Samples.MakeAddin.MakeAddinFromMacroProj. This will bring up the input box shown in Figure 4-11. In the box, type the name of the macro project you want to turn into an add-in, and then click OK.


Figure 4-11. Specifying the macro project you want to turn into an add-in



At this point, if all the projects are of the right type, you should see a message asking you to confirm that you want to run the macro on the current project. Click OK, and the MakeAddin macro project will complete its work. When the macro is finished, you'll see the dialog box shown in Figure 4-12. What the MakeAddin macro has done is add the macro functionality from your project to the new add-in.


Figure 4-12. The message box confirming completion and final instructions for the MakeAddin macro



To test the new add-in, press F5 to start debugging; you should see a second instance of the Visual Studio .NET IDE open. On the Tools menu of that second instance of the IDE, you should see a menu containing the name of your project and the name of the macros that were in your original macro project. You can see in Figure 4-13 that the AutoHideToggle add-in is ready to go. Choosing this menu command does exactly what running the macro in the IDE did in Chapter 1.

Note

If you use this add-in or the macro described in Chapter 1, keep in mind that the layout you have open will become your default layout. It won't overwrite the layouts that ship with Visual Studio .NET, but if you want to get back to one of those, you'll need to go back to the My Profile tab on the Start Page and select an alternative layout in the Windows Layout list. Then select the layout you chose when you originally created your profile and your windows should return to that layout.


Figure 4-13. The new AutoHideToggle add-in in the IDE



To use this new add-in in Visual Studio .NET, you build a release version of the setup project that's generated for the add-in and then you navigate to the folder containing the setup program. Close all your instances of Visual Studio .NET and run the Setup.exe program. When you open the IDE, you'll find that your new add-in has been installed and is ready for use.


/ 118