在Powershell v5.1中…如果我使用这个命令安装.NET NuGet包(例如: redmine-api ):
Install-Package redmine-api
那么如何从该包中创build一个用于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.
正如@Matthew指出的那样,当我尝试将名称空间加载到对象中时,它不工作。 正确的方法是:
[reflection.assembly]::LoadWithPartialName("Redmine.Net.Api") $rdm = New-Object Redmine.Net.Api.RedmineManager
查看包的文档 ,程序集名称与using Redmine.Net.Api ,而对象名称与C#源代码中的new RedmineManager(host, apiKey) 。