Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.build/runbuild.ps1: Changed to edit the global.json file instead of overwriting it to account for any future changes to it. #991

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions .build/runbuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ task Clean -description "This task cleans up the build directory" {

task UpdateLocalSDKVersion -description "Backs up the project.json file and pins the version to $minimumSdkVersion" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but the description refers to the "project.json" file when I think it should be "global.json"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Leftovers from the dnx days, I guess.

Backup-File $globalJsonFile
Generate-Global-Json `
Update-Global-Json `
-sdkVersion $minimumSdkVersion `
-file $globalJsonFile
}
Expand Down Expand Up @@ -484,25 +484,43 @@ function Update-LuceneCLI-Readme-For-Pack([string]$version) {
} | Set-Content $luceneCLIReadmeFile -Force
}

function Generate-Global-Json {
function Update-Global-Json {
param(
[string]$sdkVersion,
[string]$file = $(throw "file is a required parameter.")
)

$fileText = "{
""sources"": [ ""src"" ],
""sdk"": {
""version"": ""$sdkVersion"",
""rollForward"": ""latestMajor""
}
}"
$dir = [System.IO.Path]::GetDirectoryName($file)
Ensure-Directory-Exists $dir

# Read existing JSON file if it exists
if (Test-Path $file) {
$jsonContent = Get-Content $file -Raw | ConvertFrom-Json
} else {
# Create a new object if the file doesn't exist
$jsonContent = [pscustomobject]@{
"msbuild-sdks" = @{
"Microsoft.Build.NoTargets" = "3.7.56"
}
"sources" = @("src")
}
}

# Ensure sdk is an object, even if it exists but is null
if (-not $jsonContent.PSObject.Properties.Match('sdk') -or $null -eq $jsonContent.sdk) {
# Add the "sdk" property if it doesn't exist
$jsonContent | Add-Member -MemberType NoteProperty -Name "sdk" -Value @{}
}

# Now update the sdk properties
$jsonContent.sdk.version = $sdkVersion
$jsonContent.sdk.rollForward = "latestMajor"

Write-Host "Generating global.json file: $(Normalize-FileSystemSlashes "$file")"
Track-Added-File $file
Out-File -filePath $file -encoding UTF8 -inputObject $fileText

# Convert the updated object back to JSON and write it to the file
$jsonContent | ConvertTo-Json -Depth 10 | Set-Content -Path $file -Encoding UTF8
}

function Generate-Version-Props {
Expand Down