【发布时间】:2023-02-25 21:40:11
【问题描述】:
我正在尝试使用 powershell 和 iCal.Net 包读取 .ics 文件。
# install prerequisites
# Install-Package NodaTime -Force
# Install-Package iCal.Net -Force
# load assemblies
Write-Host loading assemblies -ForegroundColor Green
Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package ICal.Net).Source) lib\netstandard2.0\Ical.Net.dll)
Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package NodaTime).Source) lib\netstandard2.0\NodaTime.dll)
Add-Type -LiteralPath (Join-Path (Split-Path -Parent (Get-Package NodaTime).Source) lib\net6.0\NodaTime.dll)
# set variables
Write-Host defining ics url -ForegroundColor Green
$icsurl = "https://url_to/basic.ics"
# download ics
Write-Host invoking web request -ForegroundColor Green
$response = Invoke-WebRequest $icsurl
# create calendar object
Write-Host creating calendar object -ForegroundColor Green
$calendar = New-Object Ical.Net.Calendar
# deserialize ICS
Write-Host deserializing ics -ForegroundColor Green
$calendar = [Ical.Net.Calendar]::Load( $response.Content )
尝试加载 .ics 文件时,无论我选择哪个选项,我都会收到错误消息
这是错误
Method invocation failed because [Ical.Net.Calendar] does not contain a method named 'Calendar'.
At line:1 char:1
+ $calendar.Calendar($icsfile)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
有什么办法可以获得此软件包功能的列表吗?我查看了 Get-Command 选项,但它适用于模块,这是一个包。
我的目标是在 .ics 文件中生成一个可用事件表,并显示开始日期、开始时间和摘要。
根据 cmets 更新代码以显示加载 NodaTime ddl 和反序列化 ics 文件的命令。新的错误是:
Exception calling "Load" with "1" argument(s): "Could not load file or assembly 'NodaTime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1' or one of its dependencies. The
system cannot find the file specified."
At C:\Users\Windows\Desktop\repo\test.ps1:26 char:1
+ $calendar = [Ical.Net.Calendar]::Load( $response.Content )
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
【问题讨论】:
-
日历和属性还是一种方法?错误说“方法”。
标签: powershell package-management