|
1 | 1 | # Get the source directory from command line argument or use default "src"
|
2 | 2 | param(
|
3 | 3 | [string]$SourceDir = "src",
|
4 |
| - [string]$TestFramework = "none" # Default to "none" if not specified |
| 4 | + [string]$TestFramework = "none", # Default to "none" if not specified |
| 5 | + [string]$OfficeApp = "automatic" # Default to "automatic" if not specified |
5 | 6 | )
|
6 | 7 |
|
7 | 8 | Write-Host "Current directory: $(pwd)"
|
@@ -35,21 +36,35 @@ function Get-OfficeApp {
|
35 | 36 | }
|
36 | 37 | }
|
37 | 38 |
|
38 |
| -# Create a list of Office applications that are needed based on the file extensions of the folders |
39 |
| -foreach ($folder in $folders) { |
40 |
| - $FileExtension = $folder.Substring($folder.LastIndexOf('.') + 1) |
41 |
| - $app = Get-OfficeApp -FileExtension $FileExtension |
42 |
| - |
43 |
| - if ($app) { |
44 |
| - if ($officeApps -notcontains $app) { |
45 |
| - $officeApps += $app |
| 39 | +if ($OfficeApp -ieq "automatic") { |
| 40 | + |
| 41 | + # Create a list of Office applications that are needed based on the file extensions of the folders |
| 42 | + foreach ($folder in $folders) { |
| 43 | + $FileExtension = $folder.Substring($folder.LastIndexOf('.') + 1) |
| 44 | + $app = Get-OfficeApp -FileExtension $FileExtension |
| 45 | + |
| 46 | + if ($app) { |
| 47 | + if ($officeApps -notcontains $app) { |
| 48 | + $officeApps += $app |
| 49 | + } |
| 50 | + } else { |
| 51 | + Write-Host "Unknown file extension: $FileExtension. Skipping..." |
| 52 | + continue |
46 | 53 | }
|
47 |
| - } else { |
48 |
| - Write-Host "Unknown file extension: $FileExtension. Skipping..." |
49 |
| - continue |
| 54 | + } |
| 55 | + |
| 56 | +} else { |
| 57 | + # We parse the OfficeApp parameter to get the list of Office applications |
| 58 | + $officeApps = $OfficeApp -split "," |
| 59 | + $officeApps = $officeApps | ForEach-Object { $_.Trim() } |
| 60 | + $officeApps = $officeApps | Where-Object { $_ -in @("Excel", "Word", "PowerPoint", "Access") } |
| 61 | + if ($officeApps.Count -eq 0) { |
| 62 | + Write-Host "No valid Office applications specified. Exiting script." |
| 63 | + exit 1 |
50 | 64 | }
|
51 | 65 | }
|
52 | 66 |
|
| 67 | + |
53 | 68 | # We need to open and close the Office applications before we can enable VBOM
|
54 | 69 | Write-Host "Open and close Office applications"
|
55 | 70 | . "$PSScriptRoot/scripts/Open-Close-Office.ps1" $officeApps
|
|
0 commit comments