View Full Version : Returning variable from PowerShell subroutine
cholzwarth
03-19-2012, 10:16 AM
I have a PowerShell subroutine that does string manipulations. I can get the resulting string that I want. Is there a way to set the result to a variable that Visual Build Pro will see when the subrouting exits?
kinook
03-19-2012, 11:10 AM
One way to return values from PowerShell to VBP is via global macros.
http://www.kinook.com/VisBuildPro/Manual/powershelltab.htm
cholzwarth
03-19-2012, 12:30 PM
What I get when I try this is:
3/19/2012 1:24:58 PM: Building project step 5 - Subroutine Call...
3/19/2012 1:24:58 PM: Building subroutine step 1 - PS_to_VB_Macro...
3/19/2012 1:24:59 PM: Building subroutine step 2 - PowerShell...
New-Object : Cannot load COM type VisBuildSvr.Application.
At C:\DOCUME~1\CM-PAY~1\LOCALS~1\Temp\VisBAD.tmp.ps1:3 char:18
+ $app = New-Object <<<< -com VisBuildSvr.Application
You cannot call a method on a null-valued expression.
At C:\DOCUME~1\CM-PAY~1\LOCALS~1\Temp\VisBAD.tmp.ps1:6 char:22
+ $global = $app.Macros( <<<< 2)
You cannot call a method on a null-valued expression.
At C:\DOCUME~1\CM-PAY~1\LOCALS~1\Temp\VisBAD.tmp.ps1:12 char:12
+ $global.Add( <<<< "XYZ", "val1`tval2")
You cannot call a method on a null-valued expression.
At C:\DOCUME~1\CM-PAY~1\LOCALS~1\Temp\VisBAD.tmp.ps1:15 char:13
+ $global.Save( <<<< )
3/19/2012 1:25:02 PM: Build successfully completed (elapsed = 00:00:04).
The script:
# create app object
$app = New-Object -com VisBuildSvr.Application
# retrieve global macros
$global = $app.Macros(2)
# WRITE A VALUE TO Visual Build
# create/update macro with two values delimited by tab
$global.Add("XYZ", "val1`tval2")
# save changes to global macros (accessible in the following steps in Visual Build)
$global.Save()
kinook
03-19-2012, 01:38 PM
If you're running v7, you'll need to use VisBuildSvr7.Application (version-independent ProgID is new in v8).
cholzwarth
03-19-2012, 02:08 PM
The system I am using for builds is a 32 bit system. Is there a 32 bit version of Visual Build Pro 8?
I did get my kluge working - write to a file then read the first line from the file...
kinook
03-19-2012, 02:28 PM
Yes, the main download at http://www.kinook.com/Download/VisBuildProEval.exe is the 32-bit edition.
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.