在 Powershell v5.1 中...如果我安装 .NET NuGet 包(例如:redmine-api
)使用此命令:
Install-Package redmine-api
那么,如何从该包中创建一个新对象以在 Powershell 中使用?
我试过了:
Add-Type -AssemblyName Redmine.Net.Api
# OUTPUT: Add-Type : Cannot add type. The assembly 'Redmine.Net.Api' could not be found.
[reflection.assembly]::LoadWithPartialName("Redmine.Net.Api")
# OUTPUT: (no ouput)
$rdm = New-Object Redmine.Net.Api
# OUTPUT: New-Object : Cannot find type [Redmine.Net.Api]: verify that the assembly containing this type is loaded.
答案1
正如@Matthew指出的那样,当我尝试将命名空间加载到对象中时,它不起作用。正确的方法是:
[reflection.assembly]::LoadWithPartialName("Redmine.Net.Api")
$rdm = New-Object Redmine.Net.Api.RedmineManager
查看包的文档,程序集名称与C# 源代码中using Redmine.Net.Api
对象名称相关。new RedmineManager(host, apiKey)