如何将C#控制台应用程序转换为PowerShell?

3
我是一个有用的助手,可以翻译文本。

我正在尝试将以下c#控制台应用程序转换为powershell脚本。到目前为止,已经转换的PowerShell脚本卡在了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)});  

1
我尽力发布了这则广告,以免得到负面评价。我应该再做些什么呢?我很乐意进行修改。 - change picture
дҪ жғізҹҘйҒ“еҰӮдҪ•д»ҺPowerShellи®ҝй—®SPSolutionLanguagePackзҡ„private static ExtractCabFiles(string folder, string solution)ж–№жі•еҗ—пјҹ - Jodrell
http://csharpening.net/?p=491 - Jodrell
答案是“是”的,对于Jodress。 - change picture
2
你不必真的重写你的C#代码才能在PowerShell中运行:http://netpl.blogspot.com/2012/05/easy-way-to-become-powershell.html - Wiktor Zychla
1个回答

0

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接