My random rumblings

Something of everything and nothing at all

Strong Named PowerShell Type

Example on how to add a strongly typed Type in PowerShell

 

$Source = @"

using System;

 

public class SomeClass

{

public string SomeMethod

{

return "The result";

}

}

"@

 

$keyFile = "$((Get-Item -Path '.\' -Verbose).FullName)\deploy.snk"

$compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters

$compilerParameters.CompilerOptions = "/keyfile:$keyFile"

$compilerParameters.ReferencedAssemblies.Add("System.dll")

Add-Type -TypeDefinition $Source -Language CSharp -CompilerParameters $compilerParameters

Loading