我创建了一个C#类库,该库将承载许多PowerShell Core(6.1.2)Cmdlet。
该项目包括两个NuGet软件包:
New-Session
Cmdlet:
using System;
using System.Management.Automation;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
namespace PsOracleCore.Cmdlets
{
[Cmdlet(VerbsCommon.New, "Session")]
[OutputType(typeof(OracleConnection))]
public class NewSessionCmdlet : Cmdlet
{
[Parameter(Position = 0)]
[ValidateNotNullOrEmpty]
public string Account { get; set; }
[Parameter(Position = 1)]
[ValidateNotNullOrEmpty]
public string Password { get; set; }
[Parameter(Position = 2)]
[ValidateNotNullOrEmpty]
public string DataSource { get; set; }
protected override void ProcessRecord()
{
string connectionString = String.Format("User Id={0};Password={1};Data Source={2};",this.Account,this.Password,this.DataSource);
OracleConnection connection = new OracleConnection();
connection.ConnectionString = connectionString; connection.Open();
WriteObject(connection);
}
} // class
} // namespace
xUnit测试(包括对项目的引用)按预期工作。
将模块导入pwsh
会话(在OS X上)后,我尝试使用Cmdlet:
$ pwsh
PowerShell 6.1.2
Copyright (c) Microsoft Corporation. All rights reserved.
PS [project]/bin/Debug/netcoreapp2.1> import-module PsOracleCore
PS [project]/bin/Debug/netcoreapp2.1> new-session
Could not load file or assembly 'Oracle.ManagedDataAccess, Version=2.0.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342'. The system cannot find the file specified.
At line:1 char:1
+ new-session
+ ~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException
我能够通过在项目的/bin/Debug/netcoreapp2.1
目录中创建到程序集的符号链接来消除该错误:
$ ln -s ~/.nuget/packages/oracle.manageddataaccess.core/2.18.3/lib/netstandard2.0/Oracle.ManagedDataAccess.dll Oracle.ManagedDataAccess.dll
我的项目中缺少什么吗?
如果我想分发Cmdlet的程序集,我该怎么做才能确保正确安装和引用NuGet软件包?