-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Scripts to update to .NET prerelease version #12284
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
Changes from all commits
e7099fe
eea4ae4
e49715b
74df602
9cd2631
45c4f93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "channel": "release", | ||
| "packageVersionPattern": "5.0.0-preview.2" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| [CmdletBinding()] | ||
adityapatwardhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| param ( | ||
| ) | ||
|
|
||
| <# | ||
| .DESCRIPTION Update the global.json with the new SDK version to be used. | ||
| #> | ||
| function Update-GlobalJson([string] $Version) { | ||
adityapatwardhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $psGlobalJsonPath = Resolve-Path "$PSScriptRoot/../global.json" | ||
| $psGlobalJson = Get-Content -Path $psGlobalJsonPath -Raw | ConvertFrom-Json | ||
| $psGlobalJson.sdk.version = $Version | ||
| $psGlobalJson | ConvertTo-Json | Out-File -FilePath $psGlobalJsonPath -Force | ||
| } | ||
|
|
||
| <# | ||
| .DESCRIPTION Iterate through all the csproj to find all the packages that need to be updated | ||
| #> | ||
| function Update-PackageVersion { | ||
|
|
||
| class PkgVer { | ||
| [string] $Name | ||
| [string] $Version | ||
| [string] $NewVersion | ||
| [string] $Path | ||
|
|
||
| PkgVer($n, $v, $nv, $p) { | ||
| $this.Name = $n | ||
| $this.Version = $v | ||
| $this.NewVersion = $nv | ||
| $this.Path = $p | ||
| } | ||
| } | ||
|
|
||
| $skipModules = @( | ||
| "NJsonSchema" | ||
| "Markdig.Signed" | ||
| "PowerShellHelpFiles" | ||
| "Newtonsoft.Json" | ||
| "Microsoft.ApplicationInsights" | ||
| "Microsoft.Management.Infrastructure" | ||
| "Microsoft.PowerShell.Native" | ||
| "Microsoft.NETCore.Windows.ApiSets" | ||
| ) | ||
|
|
||
| $packages = [System.Collections.Generic.Dictionary[[string], [PkgVer]]]::new() | ||
|
|
||
| Get-ChildItem -Path "$PSScriptRoot/../src/" -Recurse -Filter "*.csproj" -Exclude 'PSGalleryModules.csproj' | ForEach-Object { | ||
| $prj = [xml] (Get-Content $_.FullName -Raw) | ||
| $pkgRef = $prj.Project.ItemGroup.PackageReference | ||
|
|
||
| foreach ($p in $pkgRef) { | ||
| if ($null -ne $p -and -not $skipModules.Contains($p.Include)) { | ||
| if (-not $packages.ContainsKey($p.Include)) { | ||
| $packages.Add($p.Include, [PkgVer]::new($p.Include, $p.Version, $null, $_.FullName)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $versionPattern = (Get-Content "$PSScriptRoot/../DotnetRuntimeMetadata.json" | ConvertFrom-Json).sdk.packageVersionPattern | ||
|
|
||
| $packages.GetEnumerator() | ForEach-Object { | ||
| $pkgs = Find-Package -Name $_.Key -AllVersions -AllowPreReleaseVersions -Source 'dotnet5' | ||
|
|
||
| $version = $_.Value.Version | ||
|
|
||
| foreach ($p in $pkgs) { | ||
| if ($p.Version -like "$versionPattern*") { | ||
| if ([System.Management.Automation.SemanticVersion] ($version) -lt [System.Management.Automation.SemanticVersion] ($p.Version)) { | ||
| $_.Value.NewVersion = $p.Version | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $pkgsByPath = $packages.Values | Group-Object -Property Path | ||
|
|
||
| $pkgsByPath | ForEach-Object { | ||
| Update-CsprojFile -Path $_.Name -Values $_.Group | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .DESCRIPTION Update package versions to the latest as per the pattern mentioned in DotnetRuntimeMetadata.json | ||
| #> | ||
| function Update-CsprojFile([string] $path, $values) { | ||
| $fileContent = Get-Content $path -raw | ||
| $updated = $false | ||
|
|
||
| foreach ($v in $values) { | ||
| if ($v.NewVersion) { | ||
| $stringToReplace = "<PackageReference Include=`"$($v.Name)`" Version=`"$($v.Version)`" />" | ||
| $newString = "<PackageReference Include=`"$($v.Name)`" Version=`"$($v.NewVersion)`" />" | ||
|
|
||
| $fileContent = $fileContent -replace $stringToReplace, $newString | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is doing a regex replace... maybe it's safer to using .replace()
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regex replace is turning out to be a bit complicated. Keeping it as is. The intention is to create a PR after the script does the changes. So there will be a code review as a safety net. |
||
| $updated = $true | ||
| } | ||
| } | ||
|
|
||
| if ($updated) { | ||
| $fileContent | Out-File -FilePath $path -Force | ||
| } | ||
| } | ||
|
|
||
| $dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json" | ||
| $dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json | ||
|
|
||
| # Channel is like: $Channel = "5.0.1xx-preview2" | ||
| $Channel = $dotnetMetadataJson.sdk.channel | ||
|
|
||
| Import-Module "$PSScriptRoot/../build.psm1" -Force | ||
|
|
||
| Find-Dotnet | ||
|
|
||
| if(-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) | ||
| { | ||
| $nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value | ||
| Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet | ||
| Write-Verbose -Message "Register new package source 'dotnet5'" -verbose | ||
| } | ||
|
|
||
| ## Install latest version from the channel | ||
|
|
||
| Install-Dotnet -Channel "$Channel" -Version 'latest' | ||
|
|
||
| Write-Verbose -Message "Installing .NET SDK completed." -Verbose | ||
|
|
||
| $latestSdkVersion = (dotnet --list-sdks | Select-Object -Last 1 ).Split() | Select-Object -First 1 | ||
|
|
||
| Write-Verbose -Message "Installing .NET SDK completed, version - $latestSdkVersion" -Verbose | ||
|
|
||
| Update-GlobalJson -Version $latestSdkVersion | ||
|
|
||
| Write-Verbose -Message "Updating global.json completed." -Verbose | ||
|
|
||
| Update-PackageVersion | ||
|
|
||
| Write-Verbose -Message "Updating project files completed." -Verbose | ||
Uh oh!
There was an error while loading. Please reload this page.