c# - 将 Powershell 脚本添加到 C# 项目

标签 c# powershell

所以我对编程还很陌生,所以希望有人能在这里帮助我。我正在构建一个需要 powershell 脚本的 C# 应用程序,现在虽然我知道如何使用运行空间和管道调用脚本,但此方法需要在代码中引用脚本位置,如果要使用此应用程序,这将造成问题除了我自己以外的其他人。有谁知道是否有办法将 powershell 脚本添加到项目中以便可以引用它而不是我必须引用文件位置?

最佳答案

我想到了两件事:

  1. 在 C# 中内联您的 Powershell 脚本(使用 StringBuilder 构建您的 powershell 脚本)。
  2. 将您的 powershell 脚本作为文本资源嵌入并将其作为流读取,然后执行。引用 here .

关于c# - 将 Powershell 脚本添加到 C# 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23608192/

相关文章:

c# - 类型名称 {myUserControl} 在类型 {myNamespace.myNamespace} 中不存在

c# - 如何在 C# 中使用前置/后置条件和不变量实现 Stack 类?

c# - 调用 MonoTouch.UIKit.UIDevice.CurrentDevice.SystemVersion 时发生崩溃

powershell - 尝试 Catch 在 Powershell 脚本中不起作用

git - 如何将 Bitbucket post-commit Hook shell 脚本正确转换为 Powershell 脚本?

powershell - 在 Powershell 中获取 ADFS token

c# - 如何读取特定名称的所有 XML 节点并将它们放入数组(或列表)中?

C# 不信任已安装的证书

在 PS v4 上运行时,Powershell v2.0 Foreach 循环失败

mongodb - 将 kubectl exec 的返回值获取到 powershell 脚本中