SOMS/update-projects.ps1

56 lines
3.1 KiB
PowerShell
Raw Permalink Normal View History

2025-08-11 10:39:55 +08:00
# PowerShell script to update .NET project files from netcoreapp3.1 to net6.0
# List of project files to update
$projectFiles = @(
"src\YunDa.Domain\ProtectionDeviceSqlite\YunDa.SOMS.Commdb\YunDa.SOMS.Commdb.csproj",
"src\YunDa.Domain\ProtectionDeviceSqlite\YunDa.SOMS.ProDB\YunDa.SOMS.ProDB\YunDa.SOMS.ProDB.csproj",
"src\YunDa.Quick\MigratorForDB\MigratorForDB.csproj",
"src\YunDa.Quick\SOMSUpdateProgram\SOMSUpdateProgram.csproj",
"src\YunDa.Quick\SOMSUpdateWindow\SOMSUpdateWindow.csproj",
"src\YunDa.Server\IEC104\IEC104.csproj",
"src\YunDa.Util\WebSocket\WebSocket.csproj",
"test\ConsoleAppSqlite\ConsoleAppSqlite.csproj",
"test\ConsoleISMSMysql\ConsoleISMSMysql.csproj",
"test\ConsoleTest\ConsoleTest.csproj",
"test\ConsoleTestDotnettyClient\ConsoleTestDotnettyClient.csproj",
"test\OperationsMainSiteGatewayServer\Yunda.SOMS.OperationsMainSiteGatewayServer.csproj",
"test\Web一键发布IIS\一键发布web服务.csproj",
"test\WpfAppUniqueSelectorGrid\WpfAppUniqueSelectorGrid.csproj"
)
foreach ($projectFile in $projectFiles) {
if (Test-Path $projectFile) {
Write-Host "Updating $projectFile"
# Read the file content
$content = Get-Content $projectFile -Raw
# Replace netcoreapp3.1 with net6.0
$content = $content -replace '<TargetFramework>netcoreapp3\.1</TargetFramework>', '<TargetFramework>net6.0</TargetFramework>'
# Add LangVersion if not present and there's a PropertyGroup
if ($content -notmatch '<LangVersion>' -and $content -match '<PropertyGroup>') {
$content = $content -replace '(<TargetFramework>net6\.0</TargetFramework>)', '$1`n <LangVersion>8.0</LangVersion>'
}
# Update common Microsoft.Extensions packages to 6.0 versions
$content = $content -replace 'Microsoft\.Extensions\.Configuration" Version="3\.1\.\d+"', 'Microsoft.Extensions.Configuration" Version="6.0.1"'
$content = $content -replace 'Microsoft\.Extensions\.Configuration\.Json" Version="3\.1\.\d+"', 'Microsoft.Extensions.Configuration.Json" Version="6.0.0"'
$content = $content -replace 'Microsoft\.Extensions\.Configuration\.FileExtensions" Version="3\.1\.\d+"', 'Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0"'
$content = $content -replace 'Microsoft\.Extensions\.Logging\.Console" Version="3\.1\.\d+"', 'Microsoft.Extensions.Logging.Console" Version="6.0.0"'
$content = $content -replace 'Microsoft\.Extensions\.Configuration\.EnvironmentVariables" Version="3\.1\.\d+"', 'Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1"'
# Update Newtonsoft.Json to a more recent version
$content = $content -replace 'Newtonsoft\.Json" Version="12\.0\.\d+"', 'Newtonsoft.Json" Version="13.0.3"'
# Write the updated content back to the file
Set-Content $projectFile -Value $content -Encoding UTF8
Write-Host "Updated $projectFile successfully"
} else {
Write-Host "File not found: $projectFile"
}
}
Write-Host "All project files have been updated."