SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

mac/linux support #65

Closed lprichar closed 5 years ago

lprichar commented 5 years ago

Summary

Introduces the ability to run powershell scripts on mac and linux per Issue #12. Supports Arguments and WorkingDirectory.

Limitations

To Test

  1. Add a script called hello.ps1 like:
Param(
    [parameter(Mandatory=$true)][string]$name
)
Write-Host "Hello $name"
  1. Run it in a cake script on a Mac or Linux like:
StartPowershellScript("hello.ps1", new PowershellSettings {
    Arguments = new ProcessBuilderArguments().Append("-name", "Mr Bob Dobalina")
});

Expected: "Hello Mr Bob Dobalina"

SharpeRAD commented 5 years ago

I'm really torn with with PR as on one hand we currently have no support so anythings an improvement on that but I don't think this counts as cross platform as it ignores so much core functionality.

It's really just executing a process?

lprichar commented 5 years ago

It's executing the pwsh process, which is how you run powershell scripts on a Mac afaik. I feel like this solves 90% of scenarios. It certainly solves mine, and is an improvement over something like StartAndReturnProcess("pwsh") which doesn't read as nicely, and isn't cross platform.

lprichar commented 5 years ago

btw I looked into solving the underlying "InvalidProgramException: Invalid IL code" error, but didn't make much progress. It appears that the RunspaceFactory.CreateRunspace command is fundamentally not cross platform.

SharpeRAD commented 5 years ago

Its the best solution we have so far, so I'll leave this open and see if anyone joins the conversation.

lprichar commented 5 years ago

What do you need in order to merge and publish it? Can you please provide specifics?

cmenzi commented 5 years ago

Yes, please add this. I also looking for this. In case of linux the pwsh should be executed instead of powershell.

laxmanrapolu commented 4 years ago

@lprichar : Just wanted to check how did you get past the error when cake trying to load this power shell add in (which is mentioned in issue #12 ). Could not load Addins/Cake.Powershell.0.4.7/lib/net46/System.Management.Automation.dll (missing Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35))

lprichar commented 4 years ago

I'm sorry @laxmanrapolu I don't recall getting that error. Maybe because I had .Net Core installed or was running in WSL it wasn't a problem for me?

laxmanrapolu commented 4 years ago

Thanks for the update @lprichar . WSL could be the reason why you did not see error as I have .net core too. I couldn't get past this error to make cake work in Linux containers. We use lot of Powershell scripts that cake uses, so trying some other alternatives now.