Powershell Binary Module – Could not load file or Assembly “NetMQ, Version=4.0.1.13”

  Kiến thức lập trình

I am trying to build a PowerShell binary module with the NetMQ Package (Version 4.0.1.13).

I only have created a server class with two parameters (Message and Address).

Steps to reproduce the exception:

  • Build class library (dotnet build)
  • Publish class library (dotnet publish)
  • Open PowerShell 5 console
  • Import the module (ZeroMq4Ps.dll)
  • Execute the Powershell cmdlet (Send-ZeroMQMessage)

Does anyone have inputs to fix my problem? Thank you!

ZeroMq4Ps.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AssemblyName>ZeroMq4Ps</AssemblyName>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NetMQ" Version="4.0.1.13" />
    <PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
  </ItemGroup>

</Project>

SendZeroMQMessageCmdlet.cs

using System;
using System.Management.Automation;
using NetMQ;
using NetMQ.Sockets;

[Cmdlet(VerbsCommunications.Send, "ZeroMQMessage")]
public class SendZeroMQMessageCmdlet : Cmdlet
{
    [Parameter(Mandatory = true)]
    public string Message { get; set; }

    [Parameter(Mandatory = true)]
    public string Address { get; set; }

    protected override void ProcessRecord()
    {
        using (var publisher = new PublisherSocket())
        {
            publisher.Bind(Address);
            publisher.SendFrame(Message);
        }
    }
}

Output (Sorry the text is written in german):
Output

1

LEAVE A COMMENT