我现在有一个构建定义设置,其中我所说的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启动PowerShell的x86版本?
<Exec Command="$(WinDir)\SysWOW64\WindowsPowerShell\v1.0\powershell.exe myscript.ps1"/>
如果您使用TeamBuild的工作流变种,刚刚从Syswow64资料路径火了PowerShell.exe。