p3nt4/PowerShdll

About deduced target to 2.0 and 3.5

DSKYA opened this issue · 1 comments

DSKYA commented

I have a question about deduced target to 2.0 and 3.5.
Reference System.Management.Automation.dll in your code, but this is the net framework 4.5.
For the 4.5 framework, the code works perfectly, but there are dependencies problem for the 3.5 framework.
Is there any way to solve it? For example, a System.Management.Automation.dll v2.0.I do not understand how you solved it in your code.
Thank you for your help.

Here is my modified test code:

using System;
using System.Text;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

namespace pws
{
public class pwd
{
[DllExport("main", CallingConvention = CallingConvention.Cdecl)]
public static void main(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow)
{
Runspace runspace;
runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
string cmd = @"start-process e:\test.exe";
try
{
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(cmd);
pipeline.Commands.Add("Out-String");
Collection results = pipeline.Invoke();
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
}
catch (Exception e)
{
string errorText = e.Message + "\n";
}
runspace.Close();
return;
}
}
}

DSKYA commented

The problem was solved, and I solved the problem with System.Management.Automation.dll v1.0 in my guess.