是否可以将实现PowerShell cmdlet的DLL添加到C#项目并像通常使用类一样调用其函数?问题是cmdlet没有合适的调用函数。它有invoke
和其他东西。
据我所知,另一种方法是使用System.Management.Automation
命名空间。但我担心如果我连续运行7000次这样的功能会导致性能开销。
确切地说,对于MS Dynamics Nav,我有一个像Remove-NAVApplicationObjectLanguage
这样的comdlet来处理文件和要处理的7000个文件。我想将它包装到库中,并以方便我的方式使用我的附加处理来调用它。
答案 0 :(得分:1)
Microsoft提供了博客文章Coffee Break: Use the PowerShell Runner Add-In如何从Dynamics NAV中运行其Dynamics NAV PowerShell Cmdlet。
如果您想在C#中使用它,可以使用完全相同的Microsoft.Dynamics.Nav.PowerShellRunner.dll。它位于服务层C:\ Program Files \ Microsoft Dynamics NAV \ 100 \ Service \ Add-ins \ PowerShellRunner的加载项文件夹中。
C#示例:
PowerShellRunner PowerShellRunner = PowerShellRunner.CreateInSandbox();
PowerShellRunner.WriteEventOnError = true;
PowerShellRunner.ImportModule(@"C:\Program Files(x86)\Microsoft Dynamics NAV\100\RoleTailored Client\Microsoft.Dynamics.Nav.Apps.Tools.dll");
PowerShellRunner.AddCommand("Remove-NAVApplicationObjectLanguage");
string[] sources = new string[] { "TAB9.TXT", "TAB14.TXT" };
PowerShellRunner.AddParameter("Source", sources);
PowerShellRunner.AddParameter("Destination", @".\RESULT");
PowerShellRunner.WriteEventOnError = true;
PowerShellRunner.BeginInvoke();