powershellnugetpackage-management

powershell locate and load package .dll


using PowerShell and the iCal.Net package, I want to read an .ics file.

# install ical.net dependencies
Install-Package NodaTime -Force

# install ical.net package
Install-Package iCal.Net -Force

# variables
$icsfile = "C:\Users\Windows\Desktop\ical\caalendar.ical"
$icsurl = "https://url_to_download/basic.ics"

# download ics file
Invoke-WebRequest $icsurl -OutFile $icsfile

# create new calendar object
$calendar = New-Object Ical.Net.Calendar

While creating the new calendar object I get a message saying

New-Object : Cannot find type [Ical.Net.Calendar]: verify that the assembly containing this type is loaded.
At line:1 char:13
+ $calendar = New-Object Ical.Net.Calendar
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

My guess is that even though the ical.net package is installed, it also has to be loaded. While researching on how to do this, I found that I need to provide the path to a specific .dll file.

How can I find out where this .ddl is located, and how can I load it?


Solution

  • Indeed:


    Manually loading the relevant assembly from the Ical.Net NuGet package:

    Therefore:

    Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package ICal.Net).Source) lib\netstandard2.0\Ical.Net.dll)