2014-06-20 160 views
1

我目前有一個構建定義設置,我在其中調用PowerShell腳本來執行一些「額外的工作」,如使用自定義版本號和DLL簽名。我遇到的一個問題是,在我的PowerShell腳本中,我嘗試加載程序集,以便創建特定類型的對象,並在嘗試加載程序集時收到錯誤消息。我發現我需要加載的程序集需要腳本作爲x86進程運行。使用PowerShell x86運行的TFS構建

當我將PowerShell腳本作爲Windows Powershell x86而不是常規的Windows PowerShell進程運行時,我發現了這一點。我的構建定義中有沒有一種方法可以說明我可以運行哪個過程?比如構建過程模板甚至是腳本本身?

回答

0

我曾經做過一次,所以看看自己是否還在工作。

# 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" 
    } 
} 
0

爲什麼不從MSBuild啓動x86版本的PowerShell?

<Exec Command="$(WinDir)\SysWOW64\WindowsPowerShell\v1.0\powershell.exe myscript.ps1"/> 

如果您使用TeamBuild的工作流變體,只需從SysWOW64路徑中啓動PowerShell.exe即可。

相關問題