Skip to content

Commit 790445d

Browse files
update for 24.2
1 parent 321789a commit 790445d

File tree

2 files changed

+143
-60
lines changed

2 files changed

+143
-60
lines changed

ASP.NET Core/ASP.NET Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
</PropertyGroup>
66
<Target Name="DebugEnsureNodeEnv" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
77
<!-- Ensure Node.js is installed -->

test-example.ps1

Lines changed: 142 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,10 @@ $global:BUILD_VERSION = $buildVersion
1111
$global:ERROR_CODE = 0
1212
$global:FAILED_PROJECTS = @()
1313

14-
function Install-Packages {
15-
param (
16-
[string]$folderName,
17-
[string[]]$packages,
18-
[string]$buildVersion
19-
)
20-
21-
Write-Output "`nInstalling packages in folder: $folderName"
22-
23-
# Loop through each package and install it individually
24-
foreach ($package in $packages) {
25-
$packageVersion = Get-ValidNpmVersion -PackageName $package -Version $buildVersion
26-
$packageWithVersion = "$package@$packageVersion"
27-
Write-Output "Installing $packageWithVersion..."
28-
29-
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
30-
if (-not $?) {
31-
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
32-
throw "Installation failed for $packageWithVersion in $folderName"
33-
}
34-
}
35-
36-
Write-Output "`nAll packages installed successfully in $folderName"
14+
function Test-NpmVersionExists {
15+
param ([string]$Pkg, [string]$Ver)
16+
npm view "$Pkg@$Ver" > $null 2>&1
17+
return ($LASTEXITCODE -eq 0)
3718
}
3819

3920
function Get-ValidNpmVersion {
@@ -42,12 +23,6 @@ function Get-ValidNpmVersion {
4223
[string]$Version
4324
)
4425

45-
function Test-NpmVersionExists {
46-
param ([string]$Pkg, [string]$Ver)
47-
npm view "$Pkg@$Ver" > $null 2>&1
48-
return ($LASTEXITCODE -eq 0)
49-
}
50-
5126
Write-Host "Checking $PackageName@$Version..."
5227
if (Test-NpmVersionExists -Pkg $PackageName -Ver $Version) {
5328
Write-Host "$PackageName@$Version exists."
@@ -72,12 +47,36 @@ function Get-ValidNpmVersion {
7247
return $null
7348
}
7449

50+
function Install-Packages {
51+
param (
52+
[string]$folderName,
53+
[string[]]$packages,
54+
[string]$buildVersion
55+
)
56+
57+
Write-Output "`nInstalling packages in folder: $folderName"
58+
59+
foreach ($package in $packages) {
60+
$packageVersion = Get-ValidNpmVersion -PackageName $package -Version $buildVersion
61+
$packageWithVersion = "$package@$packageVersion"
62+
Write-Output "Installing $packageWithVersion..."
63+
64+
npm install --save --save-exact --no-fund --loglevel=error --force $packageWithVersion
65+
if (-not $?) {
66+
Write-Error "`nERROR: Failed to install $packageWithVersion in $folderName"
67+
throw "Installation failed for $packageWithVersion in $folderName"
68+
}
69+
}
70+
71+
Write-Output "`nAll packages installed successfully in $folderName"
72+
}
73+
7574
function Build-Project {
7675
param (
7776
[string]$folderName
7877
)
7978
Write-Output "`nBuilding the project in folder: $folderName"
80-
79+
8180
npm run build
8281
if (-not $?) {
8382
Write-Error "`nERROR: Failed to build the project in $folderName"
@@ -99,7 +98,7 @@ function Process-JavaScriptProjects {
9998

10099
$jQueryEntry = @{
101100
Name = "jQuery";
102-
Packages = if ([version]$buildVersion -ge [version]23.1) { # `devextreme-dist` appeared in 23.1
101+
Packages = if ([version]$buildVersion -ge [version]23.1) {
103102
@("devextreme", "devextreme-dist")
104103
} else {
105104
@("devextreme")
@@ -144,56 +143,140 @@ function Process-JavaScriptProjects {
144143
Write-Output "`n--== JavaScript Projects Processing Completed ==--"
145144
}
146145

147-
function Process-DotNetProjects {
146+
function Resolve-NuGetVersionWithFallback {
148147
param (
149-
[string]$RootDirectory = "."
148+
[string]$PackageName,
149+
[string]$RequestedVersion
150150
)
151151

152-
Write-Output "`n--== Starting .NET project processing in directory: $RootDirectory ==--"
152+
function Test-PackageAvailable {
153+
param ([string]$name, [string]$ver)
154+
dotnet add package $name --version $ver > $null 2>&1
155+
return ($LASTEXITCODE -eq 0)
156+
}
157+
158+
if (Test-PackageAvailable -name $PackageName -ver $RequestedVersion) {
159+
Write-Host "$PackageName@$RequestedVersion is available."
160+
return $RequestedVersion
161+
}
162+
163+
Write-Host "$PackageName@$RequestedVersion not found. Checking for -beta and -alpha versions..."
153164

154-
$slnFiles = Get-ChildItem -Path $RootDirectory -Filter *.sln -Recurse -Depth 1
165+
$suffixes = @("beta", "alpha")
166+
foreach ($suffix in $suffixes) {
167+
$fallbackVersion = "$RequestedVersion-$suffix"
168+
if (Test-PackageAvailable -name $PackageName -ver $fallbackVersion) {
169+
Write-Host "Found $PackageName@$fallbackVersion"
170+
return $fallbackVersion
171+
}
172+
}
155173

156-
if ($slnFiles.Count -eq 0) {
157-
Write-Output "`nNo solution files (.sln) found in the specified directory at level 1."
174+
Write-Warning "No matching versions found for $PackageName@$RequestedVersion"
175+
return $null
176+
}
177+
178+
function Process-AspNetCoreProject {
179+
param (
180+
[Parameter(Mandatory = $true)]
181+
[string]$buildVersion
182+
)
183+
184+
$folderPath = Get-ChildItem -Directory |
185+
Where-Object { $_.Name -match '(?i)^ASP\.NET\s*Core$' } |
186+
Select-Object -First 1 -ExpandProperty FullName
187+
188+
if (-not $folderPath) {
189+
Write-Error "Directory matching 'ASP.NET Core' not found."
158190
return
159191
}
160192

161-
foreach ($slnFile in $slnFiles) {
162-
Write-Output "`nFound solution file: $($slnFile.FullName)"
163-
164-
try {
165-
Write-Output "`nBuilding solution: $($slnFile.FullName)"
166-
dotnet build $slnFile.FullName -c Release
193+
Write-Host "Found project directory: $folderPath"
194+
Push-Location $folderPath
195+
196+
try {
197+
$resolvedNugetVersion = Resolve-NuGetVersionWithFallback -PackageName "DevExtreme.AspNet.Core" -RequestedVersion $buildVersion
198+
if (-not $resolvedNugetVersion) {
199+
throw "No valid version found for DevExtreme.AspNet.Core"
200+
}
167201

168-
if ($?) {
169-
Write-Output "`nBuild succeeded for $($slnFile.FullName)."
170-
} else {
171-
throw "Build failed for $($slnFile.FullName)."
202+
Write-Host "Installing DevExtreme.AspNet.Core@$resolvedNugetVersion..."
203+
dotnet add package DevExtreme.AspNet.Core --version $resolvedNugetVersion
204+
205+
$packageJsonPath = Get-ChildItem -Path $folderPath -Filter "package.json" -Recurse -File -ErrorAction SilentlyContinue |
206+
Select-Object -First 1 -ExpandProperty FullName
207+
208+
if ($packageJsonPath) {
209+
Write-Host "Found package.json: $packageJsonPath"
210+
211+
try {
212+
$packageJson = Get-Content -Path $packageJsonPath -Raw | ConvertFrom-Json
213+
$updated = $false
214+
215+
if ($packageJson.dependencies.devextreme) {
216+
$validDevextremeVersion = Get-ValidNpmVersion -PackageName "devextreme" -Version $buildVersion
217+
if ($validDevextremeVersion) {
218+
$packageJson.dependencies.devextreme = $validDevextremeVersion
219+
$updated = $true
220+
}
221+
}
222+
223+
if ($packageJson.dependencies.'devextreme-dist') {
224+
$validDevextremeDistVersion = Get-ValidNpmVersion -PackageName "devextreme-dist" -Version $buildVersion
225+
if ($validDevextremeDistVersion) {
226+
$packageJson.dependencies.'devextreme-dist' = $validDevextremeDistVersion
227+
$updated = $true
228+
}
229+
}
230+
231+
if ($updated) {
232+
$packageJson | ConvertTo-Json -Depth 10 | Set-Content -Path $packageJsonPath -Encoding UTF8
233+
Write-Host "Updated package.json with valid versions."
234+
} else {
235+
Write-Host "No matching dependencies found in package.json to update."
236+
}
237+
238+
Write-Host "Installing NPM dependencies..."
239+
npm install --save --save-exact --no-fund --loglevel=error
240+
if (-not $?) {
241+
throw "Failed to install npm dependencies"
242+
}
243+
} catch {
244+
Write-Error "Failed to update package.json: $_"
172245
}
173-
} catch {
174-
Write-Error "`nERROR: $_"
175-
$global:LASTEXITCODE = 1
176-
$global:ERROR_CODE = 1
177-
$global:FAILED_PROJECTS += "ASP.NET"
246+
} else {
247+
Write-Warning "No package.json file found in '$folderPath'."
178248
}
179-
}
180249

181-
Write-Output "`nCompleted .NET project processing."
250+
Write-Host "Running dotnet build..."
251+
dotnet build
252+
if ($LASTEXITCODE -eq 0) {
253+
Write-Host "Build succeeded."
254+
} else {
255+
throw
256+
}
257+
} catch {
258+
Write-Error "An error occurred: $_"
259+
$global:LASTEXITCODE = 1
260+
$global:ERROR_CODE = 1
261+
$global:FAILED_PROJECTS += "ASP.NET Core"
262+
} finally {
263+
Pop-Location
264+
}
182265
}
183266

184267
function Write-BuildInfo {
185-
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
186-
$global:BUILD_VERSION
187-
} else {
188-
"(empty)"
268+
$BUILD_VERSION = if ($global:BUILD_VERSION -ne $null -and $global:BUILD_VERSION -ne "") {
269+
$global:BUILD_VERSION
270+
} else {
271+
"(empty)"
189272
}
190273

191274
Write-Output "Build Version: $BUILD_VERSION"
192275
}
193276

194277
Write-BuildInfo
195278
Process-JavaScriptProjects -buildVersion $global:BUILD_VERSION
196-
Process-DotNetProjects
279+
Process-AspNetCoreProject -buildVersion $global:BUILD_VERSION
197280

198281
Write-Output "`nFinished testing version: $global:BUILD_VERSION. Error code: $global:ERROR_CODE"
199282
if ($global:ERROR_CODE -ne 0 -and $global:FAILED_PROJECTS.Count -gt 0) {

0 commit comments

Comments
 (0)