[英]TFS Build using PowerShell x86 to run
我目前有一個構建定義設置,我在其中調用PowerShell腳本來做一些“額外的工作”,例如使用自定義版本號和DLL簽名。 我遇到的一個問題是,在PowerShell腳本中,我試圖加載程序集,以便可以創建某種類型的對象,並且在嘗試加載程序集時出現錯誤。 我發現需要加載的程序集要求腳本作為x86進程運行。
當我將PowerShell腳本作為Windows Powershell x86而不是常規Windows PowerShell進程運行時,我發現了這一點。 我的構建定義中是否有一種方法可以聲明可以作為哪個進程運行? 例如構建過程模板,甚至在腳本本身中?
我過去做過一次,所以請親自看看它是否仍在工作。
# Get the path where powershell resides. If the caller passes -use32 then
# make sure we are returning back a 32 bit version of powershell regardless
# of the current machine architecture
function Get-PowerShellPath() {
param ( [switch]$use32=$false,
[string]$version="1.0" )
if ( $use32 -and (test-win64machine) ) {
return (join-path $env:windir "syswow64\WindowsPowerShell\v$version\powershell.exe")
}
return (join-path $env:windir "System32\WindowsPowerShell\v$version\powershell.exe")
}
# Is this a Win64 machine regardless of whether or not we are currently
# running in a 64 bit mode
function Test-Win64Machine() {
return test-path (join-path $env:WinDir "SysWow64")
}
# Is this a Wow64 powershell host
function Test-Wow64() {
return (Test-Win32) -and (test-path env:\PROCESSOR_ARCHITEW6432)
}
# Is this a 64 bit process
function Test-Win64() {
return [IntPtr]::size -eq 8
}
# Is this a 32 bit process
function Test-Win32() {
return [IntPtr]::size -eq 4
}
function Get-ProgramFiles32() {
if (Test-Win64 ) {
return ${env:ProgramFiles(x86)}
}
return $env:ProgramFiles
}
function Exec-Script32
{
param(
[string] $scriptPath
)
$scriptName = Split-Path -Leaf $scriptPath
$innerLogFilename = Join-Path $env:TEMP $scriptName
$innerLogFilename += ".log"
$dataFilename = Join-Path $env:TEMP $scriptName
$dataFilename += ".data"
Export-Clixml -Path $dataFilename -InputObject $Args
$ps32 = Get-PowershellPath -use32
Write-Verbose "### Re-entering '$scriptPath' in 32-bit shell"
Write-Verbose "### Logging to '$innerLogFilename'"
# call this exact file
& $ps32 -File $scriptPath $dataFilename 2>&1 > $innerLogFilename
$succeeded = $?
Write-Output (Get-Content $innerLogFilename)
Remove-Item $innerLogFilename
if (!$succeeded) {
#forward
throw "$scriptPath failed"
}
}
為什么不從MSBuild啟動x86版本的PowerShell?
<Exec Command="$(WinDir)\SysWOW64\WindowsPowerShell\v1.0\powershell.exe myscript.ps1"/>
如果您使用的是TeamBuild的工作流變體,只需從SysWOW64路徑中啟動PowerShell.exe。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.