-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines-net-samples.yml
More file actions
248 lines (205 loc) · 10.4 KB
/
Copy pathazure-pipelines-net-samples.yml
File metadata and controls
248 lines (205 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
trigger: none
schedules:
- cron: "0 11 * * 1"
displayName: Weekly Monday 5:00 AM (MT) Run
branches:
include:
- main
always: true
pool:
vmImage: 'windows-2022' # Use a Windows agent with Visual Studio and .NET Framework SDKs
steps:
- checkout: self
fetchDepth: 1
clean: true
- task: NuGetToolInstaller@1
displayName: 'Install NuGet'
# Task to install the MySQL ADO.NET Connector from the repository
- task: PowerShell@2
displayName: 'Install MySQL Connector/NET'
inputs:
targetType: 'inline'
script: |
# This script assumes you have downloaded the MySQL Connector MSI and placed it
# in a 'build-tools' folder in the root of your repository.
$msiName = "mysql-connector-net-9.4.0.msi"
$msiSourcePath = "$(System.DefaultWorkingDirectory)\build-tools\$msiName"
$outputFile = "$($env:TEMP)\$msiName"
if (-not (Test-Path $msiSourcePath)) {
Write-Error "MySQL Connector MSI not found at '$msiSourcePath'. Please ensure it is checked into the repository."
exit 1
}
Write-Host "Copying MySQL Connector from the repository to the temp directory..."
Copy-Item -Path $msiSourcePath -Destination $outputFile
Write-Host "Installing MySQL Connector silently..."
Start-Process msiexec.exe -ArgumentList "/i `"$outputFile`" /quiet /norestart" -Wait
Write-Host "MySQL Connector installation completed."
# New task to install the Oracle ADO.NET Connector from the repository
- task: PowerShell@2
displayName: 'Install Oracle ADO.NET Connector'
inputs:
targetType: 'inline'
script: |
# This script installs the managed Oracle driver from the zip file in the repository.
$zipName = "ODP.NET_Managed_ODAC12cR4.zip"
$zipSourcePath = "$(System.DefaultWorkingDirectory)\build-tools\$zipName"
$extractPath = "$($env:TEMP)\oracle_driver"
if (-not (Test-Path $zipSourcePath)) {
Write-Error "Oracle Connector ZIP not found at '$zipSourcePath'. Please ensure it is checked into the repository."
exit 1
}
Write-Host "Extracting Oracle Connector from $zipSourcePath..."
Expand-Archive -Path $zipSourcePath -DestinationPath $extractPath -Force
# Find the install script robustly instead of assuming the path
$installScript = Get-ChildItem -Path $extractPath -Recurse -Filter "install_odpm.bat" | Select-Object -First 1
if (-not $installScript) {
Write-Error "Could not find install_odpm.bat in the extracted files."
exit 1
}
$installFolder = $installScript.DirectoryName
Write-Host "Found install script at: $($installScript.FullName)"
Write-Host "Running Oracle driver installation script from folder: $installFolder"
Push-Location -Path $installFolder
& ".\install_odpm.bat" c:\oracle both true
Pop-Location
Write-Host "Oracle Connector installation completed."
- task: PowerShell@2
displayName: 'Build and Run All .NET Samples'
inputs:
targetType: 'inline'
script: |
# Set the script to continue even if a command writes an error
$ErrorActionPreference = "Continue"
# Define the specific directory to search for projects
$searchRoot = "Embedded .NET Engine Samples"
$searchPath = Join-Path -Path "$(System.DefaultWorkingDirectory)" -ChildPath $searchRoot
# Define the list of project folder names to exclude
$excludedFolders = @("FluentCustomCallbacks", "FluentCustomCallbacksTest", "FluentCustomFunctions", "FluentCustomFunctionsTest", "GenerateAnyDocumentCommandLine", "RunReportDB2")
# --- Find MSBuild.exe before starting ---
# Use the vswhere utility to locate the latest Visual Studio installation path
$vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
$msbuildPath = Join-Path $vsPath "MSBuild\Current\Bin\MSBuild.exe"
if (-not (Test-Path $msbuildPath)) {
Write-Error "Could not find MSBuild.exe at the expected path: $msbuildPath"
exit 1
}
Write-Host "Found MSBuild at: $msbuildPath"
# --- End MSBuild discovery ---
# Check if the specified directory exists
if (-not (Test-Path -Path $searchPath -PathType Container)) {
Write-Error "The specified search directory does not exist: $searchPath"
exit 1
}
Write-Host "Searching for projects in: $searchPath"
# Find all .csproj files recursively from the specified directory
$csprojFiles = Get-ChildItem -Path $searchPath -Recurse -Filter *.csproj
if (-not $csprojFiles) {
Write-Host "No .csproj files found in the specified directory. Pipeline will succeed."
exit 0
}
# Initialize lists to track success and failure
$successProjects = @()
$failedProjects = @()
Write-Host "Found $($csprojFiles.Count) project files. Filtering for console applications..."
$consoleProjects = @()
# Loop through all found projects to identify which ones are console apps (<OutputType>Exe</OutputType>)
foreach ($file in $csprojFiles) {
try {
[xml]$projContent = Get-Content -Path $file.FullName
if ($projContent.Project.PropertyGroup.OutputType -eq 'Exe') {
# Check if the project's parent folder name is in the exclusion list
if ($excludedFolders -contains $file.Directory.Name) {
Write-Host " [-] Skipping excluded project: $($file.Name) in folder $($file.Directory.Name)"
} else {
Write-Host " [+] Identified Console App: $($file.Name)"
$consoleProjects += $file
}
}
} catch {
Write-Warning "Could not parse $($file.FullName). It might be an older format or invalid. Skipping."
}
}
if (-not $consoleProjects) {
Write-Host "No console application projects were found (after exclusions). Pipeline will succeed."
exit 0
}
Write-Host "-----------------------------------------------------------------"
Write-Host "Starting build and run for $($consoleProjects.Count) identified console project(s)."
Write-Host "-----------------------------------------------------------------"
# Process each identified console project
foreach ($project in $consoleProjects) {
$projectName = $project.Name
$projectPath = $project.FullName
$hasFailed = $false
Write-Host "##[group]Processing Project: $projectName"
# Step 1: Restore NuGet packages using nuget.exe
Write-Host "Restoring NuGet packages for: $projectPath"
nuget restore $projectPath
if ($LASTEXITCODE -ne 0) {
$errorMessage = "NuGet restore FAILED for project: $projectName"
Write-Error $errorMessage
Write-Host "##vso[task.logissue type=error;]$errorMessage"
$hasFailed = $true
} else {
Write-Host "NuGet restore SUCCEEDED."
# Step 2: Build the project using the full path to MSBuild
Write-Host "Building project with MSBuild: $projectPath"
& $msbuildPath $projectPath /nologo /nr:false /p:Configuration=Debug
if ($LASTEXITCODE -ne 0) {
$errorMessage = "Build FAILED for project: $projectName"
Write-Error $errorMessage
Write-Host "##vso[task.logissue type=error;]$errorMessage"
$hasFailed = $true
} else {
Write-Host "Build SUCCEEDED."
# Step 3: Run the compiled .exe
# Construct the path to the output executable
$exePath = Join-Path -Path $project.DirectoryName -ChildPath "bin\Debug\$($project.BaseName).exe"
if (-not (Test-Path $exePath)) {
$errorMessage = "Could not find compiled executable at: $exePath"
Write-Error $errorMessage
Write-Host "##vso[task.logissue type=error;]$errorMessage"
$hasFailed = $true
} else {
$exeDir = Split-Path -Path $exePath -Parent
Write-Host "Setting working directory to executable's location: $exeDir"
Push-Location -Path $exeDir
Write-Host "Executing: .\$($project.BaseName).exe"
# Execute by name, explicitly referencing the current directory with '.\'
& ".\$($project.BaseName).exe"
if ($LASTEXITCODE -ne 0) {
$errorMessage = "Execution FAILED for project: $projectName. The application returned a non-zero exit code: $LASTEXITCODE"
Write-Error $errorMessage
Write-Host "##vso[task.logissue type=error;]$errorMessage"
$hasFailed = $true
} else {
Write-Host "Execution SUCCEEDED (Exit Code: 0)."
}
# Return to the original directory
Pop-Location
}
}
}
# Add the project to the appropriate success or failure list
if ($hasFailed) {
$failedProjects += $projectName
} else {
$successProjects += $projectName
}
Write-Host "##[endgroup]"
}
# --- Final Summary ---
Write-Host "-----------------------------------------------------------------"
Write-Host "Final Summary"
Write-Host "-----------------------------------------------------------------"
Write-Host "✅ Successful projects: $($successProjects.Count)"
$successProjects | ForEach-Object { Write-Host " - $_" }
Write-Host "❌ Failed projects: $($failedProjects.Count)"
$failedProjects | ForEach-Object { Write-Host " - $_" }
Write-Host "-----------------------------------------------------------------"
# Fail the pipeline if any project failed
if ($failedProjects.Count -gt 0) {
Write-Error "$($failedProjects.Count) project(s) failed. See logs for details."
exit 1
}
Write-Host "✅ All console projects were built and ran successfully!"