View Single Post
Old 09-30-2004, 03:08 PM
kevina kevina is online now
Registered User
Join Date: 03-27-2003
Posts: 825
You are correct (I should have known better, somehow my quick test looked like it worked but didn't).

The help contents do cover this (that you have to restart the build after adding a macro via script to be added to the environment variables), but also mention the advanced.bld sample as describing a workaround (dynamically creating a bld to add the macro(s), and running it first).

Here is an adaptation of that sample demonstrating a working workaround <grin>.

' this method creates a new project, does not save it, and builds
' the temporary in-memory project without showing a GUI

' the generated project has two Set Macro steps marked to update
' environment variables, to work around the fact that environment
' variables are not updated immediately from script code; they
' are from a Set Macro action run in the same process

Option Explicit

Dim objApp, objBld, objStep, objMacro

' create VisBuildPro app and build objects and connect
Set objBld = CreateObject("VisBuildSvr.Builder")
Set objApp = CreateObject("VisBuildSvr.Application")
objBld.Initialize objApp

' create an empty LOGFILE macro to disable logging of the
' temporary project
Set objMacro = objApp.Project.Macros.Add("LOGFILE", "")

' create a couple macros updating environment variables
' calls project script function AddSetMacroStep
AddSetMacroStep objApp.Project, "ENV_Macro", "ENV_MACRO Value"

' build the generated project

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"

' add a Set Macro step to the project to create the
' given macro, marking to update environment variables
Sub AddSetMacroStep(objProj, macroName, macroValue)

Dim objStep, objMacro

' add a Set Macro step and set its properties
Set objStep = objApp.Project.Steps(vbldStepMain).Add("Set Macro")
objStep.Name = "Create Macro"
objStep.Indent = 0
objStep.Property("MacroType") = vbldMacroTemporary
objStep.Property("MacroName") = macroName
objStep.Property("MacroValue") = macroValue
objStep.Property("MacroEnvVar") = True

End Sub
Reply With Quote