无法按名称解析程序集 Microsoft.PowerShell.Commands.Management.resources

时间:2021-01-08 10:57:11

标签: powershell installshield

我正在尝试通过 Installshield 的自定义操作中使用的 PowerShell 更新一个 .ini 文件:

Add-Type -assembly "Microsoft.PowerShell.Commands.Management.resources"

$installdir=get-property -name 'INSTALLDIR';
$targetdir=$installdir+'KovairDevOpsAgentInstaller\WinServiceInstaller\configuration.ini'
$username=get-property -name 'IS_APP_ID';
$password=get-property -name 'IS_APP_PASSWORD';
$baseurl=get-property -name 'IS_APP_BASEURL';

$AppLine =Get-Content -Path $targetdir| Where-Object { $_ -match 'Baseurl=' }
$AppVersion = $AppLine.Replace($AppLine.Split('=')[1],$baseurl)


$AppLine1 =Get-Content -Path $targetdir| Where-Object { $_ -match 'Username=' }
$AppVersion1 = $AppLine1.Replace($AppLine1.Split('=')[1],$username) 


$AppLine2 =Get-Content -Path $targetdir| Where-Object { $_ -match 'Password=' }
$AppVersion2 = $AppLine2.Replace($AppLine2.Split('=')[1],$password) 
$AppVersioncom=$AppVersion2.Replace("==","")


$AppLine3 =Get-Content -Path $targetdir| Where-Object { $_ -match 'IsDefaultHost=' }
$AppVersion3 = $AppLine3.Replace($AppLine3.Split('=')[1],"N")

$AppLine4 =Get-Content -Path $targetdir| Where-Object { $_ -match 'TickTimeinSecond=' }
$AppVersion4 = $AppLine4.Replace($AppLine4.Split('=')[1],3)

$AppLine5 =Get-Content -Path $targetdir| Where-Object { $_ -match 'AppStreamingThreshold=' }
$AppVersion5 = $AppLine5.Replace($AppLine5.Split('=')[1],5)

Set-content -Path $targetdir -Value ""

Add-Content -Path $targetdir -Value "$AppVersion" 
Add-Content -Path $targetdir -Value "$AppVersion1" 
Add-Content -Path $targetdir -Value "$AppVersioncom"
Add-Content -Path $targetdir -Value "$AppVersion3"
Add-Content $targetdir -Value "$AppVersion4"
Add-Content -Path $targetdir -Value "$AppVersion5"

在运行安装程序时遇到以下错误:

Action start 12:31:51: UpdateKeys.
MSI (c) (D4:90) [12:31:51:534]: Invoking remote custom action. DLL: C:\Users\afreeng\AppData\Local\Temp\MSI933E.tmp, Entrypoint: m3
InstallShield: Attempting to load through CLR 4 APIs...
InstallShield: Getting meta host...
InstallShield: Enumerating available runtimes...
InstallShield: Highest available runtime: v4.0.30319
InstallShield: Trying to use highest runtime...
InstallShield: Using highest version runtime...
InstallShield: Loading assembly ClrPsHelper from resource 4097
InstallShield: Calling method with parameters [(System.UInt32)183, (System.String)C:\Users\afreeng\AppData\Local\Temp\57bed54d-7ffc-4572-a5be-e69fa422a269\updatekeys.ps1]
InstallShield: Loading Assembly Microsoft.PowerShell.Commands.Management.resources
InstallShield: Couldn't resolve assembly by name Microsoft.PowerShell.Commands.Management.resources
InstallShield: Loading Assembly Microsoft.PowerShell.Commands.Management.resources
InstallShield: Couldn't resolve assembly by name Microsoft.PowerShell.Commands.Management.resources, Version=3.0.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35
InstallShield: Loading Assembly Microsoft.PowerShell.Commands.Management.resources
InstallShield: Couldn't resolve assembly by name Microsoft.PowerShell.Commands.Management.resources, Version=3.0.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35
Action ended 12:32:01: UpdateKeys. Return value 1.

我使用的是 PowerShell 版本 5.1.17763.1490。

1 个答案:

答案 0 :(得分:0)

我遇到了这个错误 InstallShield:无法按名称解析程序集 Microsoft.PowerShell.Commands.Management.resources

所以,尝试通过添加程序集来解决问题。但是添加这个并没有解决我的问题。