如何将c#控制台转换为Powershell?

如何将c#控制台转换为Powershell?,c#,powershell,console-application,C#,Powershell,Console Application,我正在尝试将以下c#控制台应用程序转换为powershell脚本。到目前为止,转换后的电源外壳卡在电源线上。我在转换后的代码中遗漏了什么吗?这两个都是附件,因为我知道这可能会有所帮助 这是控制台代码 MethodInfo extractCab = typeof (SPSolutionLanguagePack).GetMethod("ExtractCabFiles", BindingFlags.Default |

我正在尝试将以下c#控制台应用程序转换为powershell脚本。到目前为止,转换后的电源外壳卡在电源线上。我在转换后的代码中遗漏了什么吗?这两个都是附件,因为我知道这可能会有所帮助

这是控制台代码

  MethodInfo extractCab = typeof (SPSolutionLanguagePack).GetMethod("ExtractCabFiles",
                                    BindingFlags.Default |
                                    BindingFlags.Static |
                                    BindingFlags.NonPublic);

  //extract the wsp files to the temp folder
  extractCab.Invoke(null, newobject[] {Path.GetFullPath(filesFolder), Path.GetFullPath(solutionName)});
这是转换后的代码

MethodInfo $extractCab = typeof (SPSolutionLanguagePack).GetMethod("ExtractCabFiles",
                                    BindingFlags.Default |
                                    BindingFlags.Static |
                                    BindingFlags.NonPublic);

#extract the wsp files to the temp folder
$extractCab.Invoke(null, newobject[] {Path.GetFullPath($filesFolder), Path.GetFullPath($solutionName)});  

您的powershell语法在某些地方不正确。你想要这个:

# you will need to specify the FULL namespace-qualified type name for SPSolutionLanguagePack, I don't know what that is from your post
$extractCab = [SPSolutionLanguagePack].GetMethod("ExtractCabFiles", [Reflection.BindingFlags] 'Default, Static, NonPublic')

#extract the wsp files to the temp folder
$extractCab.Invoke($null, @( [IO.Path]::GetFullPath($filesFolder), [IO.Path]::GetFullPath($solutionName)))  

我尽我最大的努力发布这个广告,这样我就不会得到负面评价。我还应该做些什么?我很乐意修改它。所以您想知道如何从PowerShell访问
SPSolutionLanguagePack
private static ExtractCabFiles(字符串文件夹,字符串解决方案)
方法吗?答案是,Jodressy是的,您不必重写您的c#东西来让它在PowerShell中工作: