【问题标题】:How to call C# method in DLL from Runbook in Azure Automation?如何从 Azure 自动化中的 Runbook 调用 DLL 中的 C# 方法?
【发布时间】:2016-11-13 18:39:25
【问题描述】:

假设我创建了一个简单的 C# 类:

public class HelloWorld
{
    public static string Start()
    {
        return "Hello World at " + DateTime.Now.ToLongTimeString();
    }
}

现在假设我将它编译成一个 DLL 并希望在外部调用“Start”方法。通过反复试验,我发现了如何从 PowerShell 中做到这一点:

[Reflection.Assembly]::LoadFile("c:\code\HelloWorld.dll")
[HelloWorld.HelloWorld]::Start()

或者这样:

Add-Type -Path "c:\code\Helloworld.dll"
[HelloWorld.HelloWorld]::Start()

两者都可以正常工作!

但假设我想捆绑此 DLL,将其加载到 Azure 自动化中,然后从 RunBook 进行调用。我该怎么做?我已经尝试了几件事,但一直出错。

【问题讨论】:

  • 你得到什么错误?
  • 解决方案是通过找出 Azure 存储“全局”模块和“用户”模块的位置来实现的。这是有效的解决方案: Add-Type -Path "C:\Modules\User\HelloWorld\HelloWorld.dll" [HelloWorld.HelloWorld]::Start()
  • 我建议将其作为答案发布在下面,以便其他人可以更清楚地看到它!

标签: c# .net azure azure-automation


【解决方案1】:

请尝试以下步骤:

1) 压缩 dll 文件,然后单击 Azure 自动化 -> 资产 -> 导入模块,如下图所示,上传压缩文件。

2) 编写如下图所示的测试代码,点击“TEST”即可得到输出

【讨论】:

  • 我使用 Microsoft.SqlServer.Dac.dll 为 DACPAC 部署做了同样的事情,但它在 Azure 自动化中不起作用。知道为什么吗?链接 - social.msdn.microsoft.com/Forums/azure/en-US/…
  • @Jambor 我以同样的方式尝试过,但出现“无效模块结构”错误。什么可以解决
猜你喜欢
  • 2022-11-11
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-24
  • 1970-01-01
相关资源
最近更新 更多