Saturday, November 3, 2018

Writing PSThar scripts that compile C# code

PowerShell run scripts inside the PSThar extension for Abiathar automatically have access to Abiathar/FleexCore2 features. But if that PowerShell code tries to use Add-Type to compile and run C# code, it may encounter errors about not being able to find a type or namespace. The solution is to provide the three Abiathar assemblies to Add-Type:
Add-Type $code -ReferencedAssemblies ([Abiathar.Interop.IAbiatharState].Assembly, [FMod.GalaxyLevels].Assembly, $Abiathar.GetType().Assembly)

For most operations, only the first assembly (the Abiathar extension API) should be necessary. The second is FleexCore2, which is needed if using that directly instead of through Abiathar's API. The Abiathar assembly itself shouldn't usually need to be referenced; relying on internal details will lead to fragile scripts.

No comments:

Post a Comment