Environment Variables


I was trying to include the build.vcs.number into a source code file before building the project.

So i added the following to the MS Build file:

<Exec Command="PowerShell -file ReplaceBuildVcsNumber.ps1" WorkingDirectory="x:\TheFolder" ContinueOnError="false"/>

the content of the Powershell script is

$content = [System.Io.File]::ReadAllText('TheFileToChange')
$revnr = [System.Environment]::GetEnvironmentVariable("BUILD_VCS_NUMBER")
$content = $content.Replace('$build.vcs.number$', $revnr)
[System.Io.File]::WriteAllText('TheFileToChange', $content)

Sadly, this does not work. The environment variable is empty.

So I tried the following:

<Exec Command="PowerShell -file ReplaceBuildVcsNumber.ps1 -rev %build.vcs.number%" WorkingDirectory="x:\dbtoolkit" ContinueOnError="false"/>

and changed the script:

param([string]$revnr = "rev")
$content = [System.Io.File]::ReadAllText('TheFileToChange')
$content = $content.Replace('$build.svn.number$', $revnr)
[System.Io.File]::WriteAllText('TheFileToChange', $content)

How can I achieve, what I want to do here?
Using Tortoise SVN I just would use keyword substitution using $WCREV$.

Thanks in advance,

Please sign in to leave a comment.