How to set a value for MSBuild property using PowerShell

蹲街弑〆低调 提交于 2019-12-11 08:18:52

问题


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?


回答1:


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

You can do the following in PowerShell:

$env:BuildDrive="H:"


来源:https://stackoverflow.com/questions/8542687/how-to-set-a-value-for-msbuild-property-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!