fix: Update TLS protocol and OpenXML installation via NuGet
This commit is contained in:
parent
783314d3a7
commit
276c1a615d
@ -5,7 +5,7 @@ Installs prerequisites for SharePoint XLS Converter application
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
# Enable TLS 1.2 for secure connections
|
# 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
|
Write-Host "Installing required modules..." -ForegroundColor Cyan
|
||||||
|
|
||||||
@ -32,24 +32,29 @@ foreach ($module in $graphModules) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install DocumentFormat.OpenXml module
|
# Install OpenXML via NuGet package (not module)
|
||||||
if (-not (Get-Module -ListAvailable -Name DocumentFormat.OpenXml)) {
|
try {
|
||||||
try {
|
# Install NuGet package provider if not exists
|
||||||
# Install NuGet package provider if not exists
|
if (-not (Get-PackageProvider -Name NuGet)) {
|
||||||
if (-not (Get-PackageProvider -Name NuGet)) {
|
Install-PackageProvider -Name NuGet -Force
|
||||||
Install-PackageProvider -Name NuGet -Force
|
|
||||||
}
|
|
||||||
Install-Module DocumentFormat.OpenXml -Scope CurrentUser -Force -AllowClobber
|
|
||||||
Write-Host "DocumentFormat.OpenXml module installed successfully" -ForegroundColor Green
|
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
Write-Host "Failed to install ${module} module: $($_.Exception.Message)" -ForegroundColor Red
|
# Install OpenXML SDK package
|
||||||
Write-Host "You may need to install the Open XML SDK manually." -ForegroundColor Yellow
|
$openXmlPackage = Install-Package DocumentFormat.OpenXml -Source https://www.nuget.org/api/v2/ -Force -SkipDependencies
|
||||||
# Do not exit, as the application might still work if the assembly is in the GAC or a known path
|
$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 {
|
catch {
|
||||||
Write-Host "DocumentFormat.OpenXml module is already installed" -ForegroundColor Yellow
|
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
|
# Check for Excel installation
|
||||||
|
|||||||
16
MainForm.ps1
16
MainForm.ps1
@ -2,20 +2,14 @@ Add-Type -AssemblyName System.Windows.Forms
|
|||||||
Import-Module Microsoft.Graph.Sites
|
Import-Module Microsoft.Graph.Sites
|
||||||
Import-Module Microsoft.Graph.Files
|
Import-Module Microsoft.Graph.Files
|
||||||
|
|
||||||
# Load Open XML assembly
|
# Load Open XML assembly from installed NuGet package
|
||||||
try {
|
try {
|
||||||
# Try loading from GAC
|
$openXmlPath = Join-Path $env:USERPROFILE ".nuget\packages\DocumentFormat.OpenXml\*\lib\net46\DocumentFormat.OpenXml.dll"
|
||||||
Add-Type -AssemblyName "DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
|
Add-Type -Path (Resolve-Path $openXmlPath -ErrorAction Stop)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
try {
|
[System.Windows.Forms.MessageBox]::Show("OpenXML assembly missing! Install dependencies first.")
|
||||||
# Try loading from a default path
|
exit
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Import our components
|
# Import our components
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user