1

In Powershell v5.1... If I install a .NET NuGet package (example: redmine-api) using this command:

Install-Package redmine-api

How do I then create a new object from that package for use in Powershell?

I've tried:

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.
Adam
  • 111
  • 5
  • 1
    It sounds like Redmind.Net.Api is the assembly name/namespace. That's not an object in itself. I don't know anything about that library/namespace, but you'll need to specify an object type. – Matthew Wetmore Jan 24 '17 at 19:55
  • You're absolutely right. Thanks for your input. I'll update with an actual answer soon, or feel free to do so yourself if you want the credits! – Adam Jan 25 '17 at 11:44

1 Answers1

0

As pointed out by @Matthew, it wasn't working as I was trying to load the namespace into the object. The correct method is:

[reflection.assembly]::LoadWithPartialName("Redmine.Net.Api")
$rdm = New-Object Redmine.Net.Api.RedmineManager

Looking at the package's docs, the Assembly name relates to using Redmine.Net.Api and the object name relates to new RedmineManager(host, apiKey) in C# source code.

Adam
  • 111
  • 5