繁体   English   中英

如何将c#console转换为Powershell?

[英]How to convert c# console to Powershell?

我试图将以下c#控制台应用程序转换为powershell脚本。 到目前为止,转换后的power-shell卡在了ExtractCabFiles线上。 我在转换后的代码中遗漏了什么吗? 两者都附上,因为我知道它可能有所帮助。

这是控制台代码

  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)))  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM