Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with [\[] [\]] with using [XML] class #23

Open
Mobe1969 opened this issue Feb 6, 2020 · 4 comments
Open

Issues with [\[] [\]] with using [XML] class #23

Mobe1969 opened this issue Feb 6, 2020 · 4 comments
Labels

Comments

@Mobe1969
Copy link

Mobe1969 commented Feb 6, 2020

I'm really struggling to get this working properly with XML objects [[]xml[]]. So if I have as a simple example. I also tried an external powershell file and got an error also, but no less detail in the log.

if ($null -eq $null) {
[[]xml[]](Get-Content $CurrentConfig)
}

It is transformed to this in the msiexec log where it prints the script being run:
if ($null -eq $null)
(Get-Content $CurrentConfig)
}
So it is now missing "{ [[]xml[]]", so both the opening brace of the block, and the expected [xml] are gone.

Looking at the msiexec verbose log, the powershell script being executed is logged, and the script not only has the [[]xml[]] removed, the preceding { on the if statement has been removed also.

See the attached fragment 1.txt - It doesn't paste as code

The log section from msiexec is in the fragment 2.txt. It won't paste inline.

If I run the script from a file (using directly [xml]), I get this:
MSI (s) (DC:F4) [12:45:15:932]: Executing op: CustomActionSchedule(Action=PowerShellFilesDeferred,ActionType=1025,Source=BinaryData,Target=PowerShellFilesDeferred,CustomActionData=xml=<r> <d Id="UpdateBindings" file="" args="" IgnoreErrors="0" /> </r>) MSI (s) (DC:F8) [12:45:15:934]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI18D1.tmp, Entrypoint: PowerShellFilesDeferred SFXCA: Extracting custom action to temporary directory: C:\WINDOWS\Installer\MSI18D1.tmp-\ SFXCA: Binding to CLR version v4.0.30319 Calling custom action PowerShellActions!PowerShellActions.CustomActions.PowerShellFilesDeferred PowerShellFilesDeferred start PowerShell terminating error, returning Failure System.Management.Automation.RuntimeException: The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at PowerShellActions.PowerShellTask.Execute() at PowerShellActions.CustomActions.FilesDeferred(Session session, String deferredProperty) CustomAction PowerShellFilesDeferred returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 12:45:16: InstallFinalize. Return value 3. MSI (s) (DC:F4) [12:45:16:724]: Note: 1: 2265 2: 3: -2147287035

@Mobe1969 Mobe1969 changed the title Issues with [\[] [\]] Issues with [\[] [\]] with using [XML] class Feb 6, 2020
@Mobe1969
Copy link
Author

Mobe1969 commented Feb 6, 2020

OK, I'll try attach as txt files...
Fragment 2.txt
fragment1.txt

@Mobe1969
Copy link
Author

Mobe1969 commented Feb 7, 2020

PS - I get the same script file error with the & one when I use the Test.ps1 from this codebase

@flcdrg flcdrg added the question label Feb 8, 2020
@flcdrg
Copy link
Owner

flcdrg commented Feb 8, 2020

Not exactly sure, but I'd suggest starting with the examples in https://github.com/flcdrg/PowerShellWixExtension/tree/master/Tests (that do have escaped square brackets), and confirm that you can get those to work correctly.

@georg-eckert-zeiss
Copy link

I too get a problem with the square brackets:

<!-- Original script -->
</powershell:Script>

<powershell:Script Id="A" Elevated="yes"><![CDATA[
try{
  $myProcess = Start-Process -NoNewWindow -PassThru -FilePath $Env:Programfiles'\A\A.exe'
  Start-Sleep -Seconds 20

  Stop-Process -Id  $myProcess.Id[\[]0[\]] -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
]]>
</powershell:Script>

Which becomes the following when launched from the MSI:

<!-- Distorted script -->
</powershell:Script>

<powershell:Script Id="A" Elevated="yes"><![CDATA[
try{
  $myProcess = Start-Process -NoNewWindow -PassThru -FilePath $Env:Programfiles'\A\A.exe'
  Start-Sleep -Seconds 20

  Stop-Process -Id  $myProcess.Id[0] -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
 -ErrorAction SilentlyContinue

  echo "Have fun"
}
catch{
	Write-Host $_
}
]]>
</powershell:Script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants