1

I have a property to specify the build drive:

<PropertyGroup>
    <BuildDrive Condition="'$(BuildDrive)'==''">Y:</Group>
</PropertyGroup>

If I want to change the build drive using a batch file, I can do as follows:

@echo off

set buildDrive=H:

:: Then call MSBuild

Msbuild /t:BuildTarget %Projectfile% %Logger%

Now I want achieve the same using PowerShell.

I tried as follows in my PowerShell script, build.ps1:

$BuildDrive=H:
MSbuild /t:BuildTarget $ProjectFile $Logger

But it is not honoring the drive letter provided through $BuildDrive. I knew I could achieve it if I passed a parameter as follows, but when the number of properties are more, this approach was not handy.

$BuildDrive=H:
Msbuild /t:BuildTarget /p:BuildDrive=$BuildDrive $projectfile $logger

How do I pass a PropertyGroup value through PowerShell?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230

1 Answers1

5

You are setting environment variables. These are available as properties in MSBuild.

You can do the following in PowerShell:

$env:BuildDrive="H:"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I think Builddrive is my own property , even if i have some property name called dummy and the condition is specified then it can be replaced by batch file. Y: I – Samselvaprabu Dec 17 '11 at 05:24
  • @Samselvaprabu - I don't understand what you are trying to say. Did you try the line given in my answer in your script? – manojlds Dec 17 '11 at 05:25
  • Wow. It works. So when condition is being passed to propertygroup, it will be considered as environment variable. is it so? – Samselvaprabu Dec 17 '11 at 05:52
  • 1
    @Samselvaprabu - Read here: http://msdn.microsoft.com/en-us/library/ms171459(v=VS.100).aspx . Also, accept as answer ( tick on the left ) – manojlds Dec 17 '11 at 05:57