Translates a Powershell Class into a C# Class and then compiles it. This class can be referenced across all .NET Languages.
Project is currently in alpha state, so there will be some bugs. Please Report them!!
Discord: ultraalex0
This Project can be found on the Powershell Gallery and can be installed with the command:
Install-Module PSDllCompilerLets say you have a Class in example.ps1:
using namespace System.Windows.Forms #namespaces can be used if needed
class ExampleClass {
[string]$Name
[string] GreetMe() {
return "Hello $($this.Name)"
}
[int] Add([int]$Num1, [int]$Num2) {
return $Num1 + $Num2
}
}Now compile it with:
Compile-Dll -Path .\example.ps1 -OutputAssembly .\example.dllYour dll can now be imported in other powershell projecs using:
using assembly example.dll #option 1
Add-Type -Path example.dll #option 2
[Reflection.Assembly]::LoadFile("example.dll") #option 3In .NET Projects by simply adding the dll to the references, installing the NuGet package "Microsoft.PowerShell.SDK" and importing it using:
//C#
using static ExampleClass;You can use functions from other modules by referencing them
#include PSDllCompiler <---------
class CompilerTest {
static [void] Compile([string]$input, [string]$output) {
Compile-Dll -Path $input -OutputAssembly $output
}
}or using the argument -ModuleReferences @("PSDllCompiler")
- Added support for multiple classes
- Added support for Write-Host, Write-Warning
- Added argument -SkipUpdate
- Fixed method-property sync (temporary fix)
- Improved ClassHandler_Powershell
- independent property sync
- partial classes
- Read-Host
- class namespaces