Reputation: 2622
I created a .NET library and I want to create a GUI that calls the library via PowerShell. In order to call cmdlet I had to add an entry to Windows registry, because that library is compiled against .NET 4.
It works fine, but not for a PowerShell host in GUI. What can I do to set up PowerShell host to run a CLR 4 snap-in?
var rsConfig = RunspaceConfiguration.Create();
var myAssembly = new AssemblyConfigurationEntry("AssemblyName", "C:\...\Assembly.dll");
rsConfig.Assemblies.Append(myAssembly);
var runSpace = RunspaceFactory.CreateRunspace(rsConfig);
runSpace.Open();
using (var ps = PowerShell.Create()) {
ps.Runspace = runSpace;
ps.AddCommand("Get-MyCmdlet");
ps.AddParameter("Param1");
ps.AddParameter("Param2");
foreach (var result in ps.Invoke()) { // CommandNotFoundException
Debug.WriteLine(result.ToString());
}
}
Upvotes: 1
Views: 155
Reputation: 2622
Problem solved. It was a little bit complicated. I wrote an article about it. Basically appending an assembly is a wrong approach. The easier way is register that assembly.
Upvotes: 1