Automated Builds in Visual Studio, or the Night Build Scenario

Microsoft Corporation

April 1, 1997

Introduction

An automated build is a project build in Visual Studio™ that can be scheduled to start at a specific time, like late at night, and finish by itself. In the add-in sample provided for automated builds, the build log can be emailed to the person of your choice. You can use an automated build for the debug, release or both configurations of your project, or you can build multiple projects.

There are four ways to automate the build process:

  1. Use or modify the AutoBuild add-in supplied with Visual Studio

  2. Create a VBScript macro for Visual Studio

  3. Export a makefile and use NMAKE

  4. Open MSDev as an Automation object and remotely handle the build

This article focuses on the first two options, building with the add-in or with a VBScript macro, examples of which are provided here. The other two options, exporting a makefile and opening MSDev as an object, are beyond the scope of this paper.

Comparison of Add-ins and VBScript Macros

An add-in is an in-process ActiveX™ component (DLL) written in any programming language (that supports ActiveX), such as Visual C++® or Visual Basic®, whereas a VBScript macro is written in the Visual Basic Scripting Edition (VBScript) language. An add-in must be coded in that language, compiled into a DLL, and then installed in Visual Studio, but a VBScript macro can be created by recording the macro as well as by typing the macro in an editor.

An add-in can access all the local computer resources as well as the object model. The VBScript macros are limited to the Developer Studio™ object model. An add-in can control another application (.EXE) easily, but a VBScript macro can only control another application that is signed and safe, like the typical Web control. An add-in can use the Windows® API to directly read from or write to files on disk (a VBScript macro can access files but not through the API).

For more on the differences between an add-in and a VBScript macro, see the topic "Differences Between VBScript Macros and Developer Studio Add-ins" (MSDN Library, Visual C++ Documentation, Developer Studio Environment User’s Guide, Automating Tasks in Developer Studio, VBScript Macros).

Loading and Setting Up the AutoBuild Add-In Sample

Visual Studio includes samples of add-ins to use or modify, including a sample that automates a build process, AutoBuild. This builds a Visual C++ or Visual J++™ project at a specified time. When the build is done, AutoBuild emails the specified user with the name of the configuration and the number of warnings or errors. You can find and copy AutoBuild to your local drive by searching the online documentation for "AutoBld," or by looking up the topic "Copying the Sample Add-ins" (MSDN Library, Visual C++ Documentation, Developer Studio Environment User’s Guide, Automating Tasks in Developer Studio, Developer Studio Add-ins).

Optionally, you can generate a build log file (*.PLG file). Any time a build occurs, the .PLG file is overwritten with the latest information. For multiple builds, save or move the .PLG file before starting the next release or debug build. The .PLG file is stored in the project directory that you build.

To set up the AutoBuild add-in, follow these steps:

  1. Copy the AutoBuild add-in to your local drive from the MSDN documentation.

  2. Build and enable AutoBuild in Visual Studio.

  3. Run AutoBuild in Windows 95

    or

    Run AutoBuild in Windows NT 4.0.

To copy the AutoBuild add-in to your local computer:

  1. Start Visual Studio and click the InfoView tab. Navigate to the Developer Studio Environment User’s Guide, then select Automating Tasks in Developer Studio, then Developer Studio Add-ins, then click Copying the Sample Add-ins.

  2. You should now be at the topic entitled "Using the Sample Add-ins." Click the sample AutoBld to copy that add-in to your computer.

To build and enable the AutoBuild add-in:

  1. After copying the add-in, click Open and open the file autobld.dsw. The default location of this file is \DevStudio\samples\src\DSSample\AddIns\AutoBld.

  2. On the Build menu, click Build AutoBld.dll.

  3. When the build is done, select the Tools menu and click Customize. Click the Add-ins and Macro Files tab.

  4. Click the Browse button.

  5. Choose Add-ins (dll) from the File Type as box or open the Debug folder in the AutoBld directory. Click Open.

To run AutoBuild in Visual Studio using Windows® 95 (Microsoft Plus! required):

  1. Start Visual Studio and disable the Tip of the Day dialog box.

  2. Click the Configure button on the AutoBuild toolbar. Set your preferences in the AutoBuild Configuration dialog box.

  3. Click Workspaces to Build and click Add to add your preferences.

  4. Click the System Agent on the Windows 95 taskbar. The System Agent appears next to the clock in the status area on the taskbar. This is only visible if you have Microsoft Plus! installed.

  5. On the Program menu, click Schedule a New Program.

  6. In the Program text box, type:

    msdev -execute AutoBuild

  7. Set the times and days for AutoBuild to run. Set any other preferences and then click OK.

To run AutoBuild in Visual Studio using Windows NT® 4.0:

  1. Start Visual Studio and disable the Tip of the Day dialog box.

  2. Click the Configure button on the AutoBuild toolbar. Set your preferences in the AutoBuild Configuration dialog box.

  3. Click Workspaces to Build and click Add to add your preferences.

  4. On the Windows NT taskbar, click Start and click Settings. Open the Control Panel and click Services.

  5. Find the Schedule agent in the list box and confirm that the Schedule shows a status of "Started" and its Startup status is set to "Automatic."

  6. If the status of the Schedule agent is not "Started," highlight the Schedule agent and click the Start button. If the Schedule agent is not set to "Automatic," click the Startup button and select Automatic from the Startup Type field in the Service dialog box.

  7. From a command prompt, use the "at" utility to set the time and date you wish to build your projects. For example (assuming that msdev.exe is on your path):
    msdev –execute AutoBuild 
    

This will launch the Developer Studio environment and execute the AutoBuild command, which starts the build of your projects.

To get help on the “at” utility, type "at ?" at the command line.

Note   You must disable the Tip of the Day dialog box in Visual Studio before activating any add-ins, such as AutoBuild, from the command line.

For more information on add-ins in Visual Studio, look up the topic "Overview: Developer Studio Add-ins" (MSDN Library, Visual C++ Documentation, Developer Studio Environment User’s Guide, Automating Tasks in Developer Studio, Developer Studio Add-ins).

Installing and Editing the VBScript Macro, DoAllFire

A VBScript macro provides another method of doing a scheduled build. There are two ways to create a VBScript macro: record one in the Visual Studio environment, or type one in as a macro file (a .DSM file). VBScript macro files can contain more than one macro. The sample VBScript macro included here, DoAllFire, builds everything in the workspace. The macro script includes code that will build just the release or debug configurations. You can easily modify the DoAllFire macro to contain your own projects and workspaces and build everything or just the configurations and files you wish.

To install the DoAllFire macro file, Buildsam.dsm:

  1. Copy the macro file, Buildsam.dsm, to your computer. You can either download the macro file to your local hard drive or print the macro and type it into Visual Studio by hand, saving it as a macro file. If you download the macro file, save the file in the Macros subdirectory of the DevStudio directory (to avoiding searching for the file later). You can download the macro file by right clicking the link to Buildsam.dsm and choosing "Save Target As" in Microsoft Internet Explorer or "Save Link As" in Netscape Navigator.

  2. On the Tools menu in Visual Studio, click Customize.

  3. Click the Add-ins and Macro Files tab. The file Buildsam.dsm should appear in the window. If the file does not appear, click the Browse button to locate the file.

  4. Load Buildsam.dsm by selecting the check box next to its name. This check mark also directs the development environment to load the file automatically when you start the environment again.

Warning   If you remove the check mark next to a macro file name, you unload it. When you unload it, all of the macros in the file lose their toolbar and keystroke assignments.

To edit a VBScript macro:

  1. On the Tools menu, click Macro.

  2. In the Macro File box, select Buildsam.dsm, which contains the macro you wish to edit. If Buildsam.dsm is not in the list, first install the file, then select it in the Macro File box.

  3. In the Macro File box, select the VBScript macro, DoAllFire, that you wish to edit.

  4. Click the Edit button.

  5. Make the appropriate changes.

  6. Save the macro.

Running the VBScript Macro, DoAllFire:

After installing the VBScript macro, you can run the macro DoAllFire in the file Buildsam.dsm. You can run macros from toolbar buttons or key sequences assigned to the macros, from the Macros dialog box, or from the command line. For more information on the first two methods, see the topic "Running VBScript Macros" (MSDN Library, Visual C++ Documentation, Developer Studio Environment User’s Guide, Automating Tasks in Developer Studio, Developer Studio VBScript Macros).

To run a macro from the command line:

  1. Disable the Tip of the Day dialog box in Visual Studio.

  2. At the command line, type:
    msdev -ex DoAllFire 
    

DoAllFire is the name of the macro. This syntax starts the Developer Studio environment, and after the main window appears, the macro starts running.

If you want Visual Studio to shut down after the build is complete, edit the macro so that it calls the Application’s object Quit method.

To automate a macro on a schedule (with Windows 95):

  1. Disable the Tip of the Day dialog box in Visual Studio.

  2. Click the System Agent on the Windows 95 taskbar. The System Agent appears next to the clock in the status area on the taskbar. This is only visible if you have Microsoft Plus! installed.

  3. On the Program menu, click Schedule a New Program.

  4. In the Program text box, type:

    msdev -ex DoAllFire

  5. Set the times and days for DoAllFire to run. Set any other preferences and then click OK.

To automate a macro on a schedule (with Windows NT):

  1. Disable the Tip of the Day dialog box in Visual Studio.

  2. On the Windows NT taskbar, click Start and click Settings. Open the Control Panel and click Services.

  3. Find the Schedule agent in the list box and confirm that the Schedule shows a status of "Started" and that its Startup status is set to "Automatic."

  4. If the status of the Schedule agent is not "Started," highlight the Schedule agent and click the Start button. If the Schedule agent is not set to "Automatic," click the Startup button and select Automatic from the Startup Type field in the Service dialog box.

  5. From a command prompt, use the “at” utility to set the time and date you wish to build your projects. For example (assuming that msdev.exe is on your path):
    msdev -ex DoAllFire 
    

This will launch the Developer Studio environment and execute the AutoBuild command, which starts the build of your projects.

To get help on the “at” utility, type "at ?" at the command line. For example, to run the macro "DoAllFire" at 1:00 AM, use the command:

AT 1:00am "msdev -ex DoAllFire" 

To debug a VBScript macro:

For more information on add-ins in Visual Studio, look up the topic "Overview: Developer Studio VBScript Macros" (MSDN Library, Visual C++ Documentation, Developer Studio Environment User’s Guide, Automating Tasks in Developer Studio, Developer Studio VBScript Macros).