在.NET Core 2.0中创建PowerShell cmdlet

时间:2017-10-24 14:39:40

标签: powershell .net-core cmdlets

我正在尝试在.NET Core 2.0中创建PowerShell命令行开关(cmdlet)。

我引用了System.Management.Automation' 4.3.0包并创建了一个简单的cmdlet:

type(x).__str__(x)

哪种方法正常。

一旦我添加参数,我就会得到一个例外:

using System.Management.Automation;

namespace CrudGenerator.PowerShell
{
    [Cmdlet(VerbsCommon.Add, "CrudOperation")]
    public class CrudOperation : Cmdlet
    {
    }

    public enum OperationType
    {
        Get,
        Put,
        Post,
        Delete,
        Search
    }
}

有:

Import-Module : Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
+ Import-Module .\CrudGenerator.PowerShell.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

我还在.NET 4.6.1类库中创建了相同的代码,然后它就像魅力一样。

0 个答案:

没有答案