如何使用PowerShell为msbuild属性设置值?

时间:2011-12-17 04:55:32

标签: powershell msbuild powershell-v2.0 msbuild-4.0

我有指定构建驱动器的属性

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

如果我想使用批处理文件更改构建驱动器,我可以执行以下操作

@echo off

set buildDrive=H:

:: Then call MSbuild 

Msbuild /t:BuildTarget %Projectfile% %Logger%

现在我想使用powershell

进行同样的操作

我在我的powershell build.ps1

中尝试了以下操作
$BuildDrive=H:
MSbuild /t:BuildTarget $ProjectFile $Logger

但它并不尊重通过$ BuildDrive提供的驱动器号。 我知道如果我按如下方式传递参数,我可以实现,但是当属性数量更多时,这种方法并不方便。

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

任何人都可以帮助如何通过powershell传递propertygroup值吗?

1 个答案:

答案 0 :(得分:4)

您正在设置环境变量。这些在msbuild中可用作属性。

您可以在Powershell中执行以下操作:

$env:BuildDrive="H:"