I want to compile a C # class that uses the COM type library in PowerShell. If using .NET assambly, then I use code

Add-Type -ReferencedAssemblies @( $assemby) -TypeDefinition $code -Language CSharp 

Where $assemby variable with .NET assambly. When you create a project in pure C #, you can add a Reference to the COM type library. And in powershell it is possible? (I know about working with COM in Powershell itself.)

  • one
    You need to do the work that msbuild does when building the project, namely: import the COM type library using the tlbimp tlbimp and add the resulting assembly to the ReferencedAssemblies parameter. - PetSerAl

1 answer 1

An example of using one of the methods from the user32.dll library:

 $signature = @" [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); "@ $SendMouseClick = Add-Type -MemberDefinition $signature -Name 'SomeName' -PassThru $SendMouseClick::mouse_event()