fix: Update TLS protocol and OpenXML installation via NuGet

This commit is contained in:
Bobby Abellana (aider) 2025-02-21 10:39:05 -08:00
parent 783314d3a7
commit 276c1a615d
2 changed files with 26 additions and 27 deletions

View File

@ -5,7 +5,7 @@ Installs prerequisites for SharePoint XLS Converter application
#>
# Enable TLS 1.2 for secure connections
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = [enum]::Parse([Net.SecurityProtocolType], "Tls12")
Write-Host "Installing required modules..." -ForegroundColor Cyan
@ -32,24 +32,29 @@ foreach ($module in $graphModules) {
}
}
# Install DocumentFormat.OpenXml module
if (-not (Get-Module -ListAvailable -Name DocumentFormat.OpenXml)) {
try {
# Install NuGet package provider if not exists
if (-not (Get-PackageProvider -Name NuGet)) {
Install-PackageProvider -Name NuGet -Force
}
Install-Module DocumentFormat.OpenXml -Scope CurrentUser -Force -AllowClobber
Write-Host "DocumentFormat.OpenXml module installed successfully" -ForegroundColor Green
# Install OpenXML via NuGet package (not module)
try {
# Install NuGet package provider if not exists
if (-not (Get-PackageProvider -Name NuGet)) {
Install-PackageProvider -Name NuGet -Force
}
catch {
Write-Host "Failed to install ${module} module: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "You may need to install the Open XML SDK manually." -ForegroundColor Yellow
# Do not exit, as the application might still work if the assembly is in the GAC or a known path
# Install OpenXML SDK package
$openXmlPackage = Install-Package DocumentFormat.OpenXml -Source https://www.nuget.org/api/v2/ -Force -SkipDependencies
$dllPath = Join-Path $openXmlPackage.PackageSource "lib\net46\DocumentFormat.OpenXml.dll"
if (Test-Path $dllPath) {
Add-Type -Path $dllPath
Write-Host "DocumentFormat.OpenXml assembly loaded successfully" -ForegroundColor Green
}
else {
throw "OpenXML DLL not found at $dllPath"
}
}
else {
Write-Host "DocumentFormat.OpenXml module is already installed" -ForegroundColor Yellow
catch {
Write-Host "Failed to install DocumentFormat.OpenXml: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "You may need to install the Open XML SDK manually from:"
Write-Host "https://www.microsoft.com/en-us/download/details.aspx?id=30425" -ForegroundColor Yellow
}
# Check for Excel installation

View File

@ -2,20 +2,14 @@ Add-Type -AssemblyName System.Windows.Forms
Import-Module Microsoft.Graph.Sites
Import-Module Microsoft.Graph.Files
# Load Open XML assembly
# Load Open XML assembly from installed NuGet package
try {
# Try loading from GAC
Add-Type -AssemblyName "DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
$openXmlPath = Join-Path $env:USERPROFILE ".nuget\packages\DocumentFormat.OpenXml\*\lib\net46\DocumentFormat.OpenXml.dll"
Add-Type -Path (Resolve-Path $openXmlPath -ErrorAction Stop)
}
catch {
try {
# Try loading from a default path
Add-Type -Path "C:\Program Files\Microsoft Office\root\Office16\DocumentFormat.OpenXml.dll"
}
catch {
[System.Windows.Forms.MessageBox]::Show("Error loading DocumentFormat.OpenXml.dll. Make sure it is installed and the path is correct.")
return
}
[System.Windows.Forms.MessageBox]::Show("OpenXML assembly missing! Install dependencies first.")
exit
}
# Import our components