|
| 1 | +--- |
| 2 | +name: update-razor-version |
| 3 | +description: Guide for updating the Razor extension version in the vscode-csharp repository. Use this when asked to update Razor, bump the Razor version, or upgrade the Razor language server version. |
| 4 | +--- |
| 5 | + |
| 6 | +# Update Razor Version |
| 7 | + |
| 8 | +This skill describes how to update the Razor extension version in the vscode-csharp repository. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +1. You must have a local clone of the `dotnet/razor` repository (commonly at `C:\Users\<username>\source\repos\razor`) |
| 13 | +2. The `roslyn-tools` CLI tool must be installed as a global .NET tool: |
| 14 | + ```powershell |
| 15 | + dotnet tool install -g Microsoft.RoslynTools --prerelease --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json |
| 16 | + ``` |
| 17 | + **Note**: After installation, the tool is invoked as `roslyn-tools` (not `dotnet roslyn-tools`) |
| 18 | +3. You must have authenticated with GitHub for `roslyn-tools`: |
| 19 | + ```powershell |
| 20 | + roslyn-tools authenticate |
| 21 | + ``` |
| 22 | +4. The Azure CLI (`az`) must be installed and you must be logged in to Azure DevOps: |
| 23 | + ```powershell |
| 24 | + az login |
| 25 | + ``` |
| 26 | + This is needed to automatically discover the latest Razor version from the official build pipeline. |
| 27 | + |
| 28 | +## Input Required |
| 29 | + |
| 30 | +- **New Razor Version** (optional): If not provided, the latest successful build version will be automatically discovered from the official Razor build pipeline. |
| 31 | + |
| 32 | +## Process |
| 33 | + |
| 34 | +### Step 1: Determine the New Version |
| 35 | + |
| 36 | +If the user provided a specific version, use that. Otherwise, query the latest successful build from the official Razor build pipeline (definition ID 262 in the `dnceng/internal` project) and extract the package version from the BlobArtifacts. |
| 37 | + |
| 38 | +The build number (e.g., `20260214.1`) is **not** the package version. The actual NuGet package version must be extracted from the build artifacts. |
| 39 | + |
| 40 | +```powershell |
| 41 | +# Get an Azure DevOps access token |
| 42 | +$token = az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" -o tsv |
| 43 | +$headers = @{ "Authorization" = "Bearer $token" } |
| 44 | +
|
| 45 | +# Get the latest successful build ID from the main branch |
| 46 | +$buildsUrl = "https://dev.azure.com/dnceng/internal/_apis/build/builds?definitions=262&resultFilter=succeeded&branchName=refs/heads/main&`$top=1&api-version=7.1" |
| 47 | +$buildId = (Invoke-RestMethod -Uri $buildsUrl -Headers $headers).value[0].id |
| 48 | +
|
| 49 | +# Get the BlobArtifacts container ID |
| 50 | +$artifactUrl = "https://dev.azure.com/dnceng/internal/_apis/build/builds/$buildId/artifacts?artifactName=BlobArtifacts&api-version=7.1" |
| 51 | +$containerId = ((Invoke-RestMethod -Uri $artifactUrl -Headers $headers).resource.data -replace '^#/(\d+)/.*', '$1') |
| 52 | +
|
| 53 | +# List files and extract the version from the RazorExtension package filename |
| 54 | +$containerUrl = "https://dev.azure.com/dnceng/_apis/resources/Containers/$containerId/BlobArtifacts?itemType=file&api-version=7.1-preview.4" |
| 55 | +$files = (Invoke-RestMethod -Uri $containerUrl -Headers $headers).value |
| 56 | +$razorFile = ($files.path | Where-Object { $_ -match 'Microsoft\.VisualStudioCode\.RazorExtension\.' }) | Select-Object -First 1 |
| 57 | +$version = $razorFile -replace '.*Microsoft\.VisualStudioCode\.RazorExtension\.(.+?)(\.symbols)?\.nupkg$', '$1' |
| 58 | +Write-Host "Latest Razor version: $version" |
| 59 | +``` |
| 60 | + |
| 61 | +This returns the NuGet package version (e.g., `10.0.0-preview.26114.1`). |
| 62 | + |
| 63 | +**Note**: If authentication fails, run `az login` first and ensure you have access to the `dnceng/internal` project. |
| 64 | + |
| 65 | +### Step 2: Create a New Branch |
| 66 | + |
| 67 | +Create a new git branch for the update: |
| 68 | +```powershell |
| 69 | +git checkout -B update/razor-<version> |
| 70 | +``` |
| 71 | +Replace `<version>` with the new Razor version, using dashes instead of dots for the branch name. |
| 72 | + |
| 73 | +### Step 3: Update package.json |
| 74 | + |
| 75 | +Update the `defaults.razor` field in `package.json`: |
| 76 | + |
| 77 | +```json |
| 78 | +"defaults": { |
| 79 | + "razor": "<new-version>", |
| 80 | + ... |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Step 4: Run gulp updateRazorVersion |
| 85 | + |
| 86 | +This step acquires the new Razor extension package and ensures it is in the proper feeds: |
| 87 | + |
| 88 | +```powershell |
| 89 | +gulp updateRazorVersion |
| 90 | +``` |
| 91 | + |
| 92 | +This task: |
| 93 | +- Downloads the `Microsoft.VisualStudioCode.RazorExtension` NuGet package |
| 94 | +- Runs `installDependencies` to update local dependencies |
| 95 | + |
| 96 | +**Note**: You may need to install the [Azure Artifacts NuGet Credential Provider](https://github.com/microsoft/artifacts-credprovider#installation-on-windows) for interactive authentication. |
| 97 | + |
| 98 | +### Step 5: Get the Previous Razor Commit SHA |
| 99 | + |
| 100 | +The commit SHAs are stored in the `.nuspec` files inside the downloaded NuGet packages. After running `gulp updateRazorVersion`, the new version's package will be cached locally, but you need to explicitly download the old version to get its commit SHA. |
| 101 | + |
| 102 | +**To get the old version's commit SHA:** |
| 103 | + |
| 104 | +1. First, find the old version number from the current `package.json` (before your edit) - look at the `defaults.razor` value |
| 105 | +2. Download the old version's package to the local cache: |
| 106 | + ```powershell |
| 107 | + dotnet restore "C:\Users\<username>\source\repos\vscode-csharp\msbuild\server" /p:PackageName=Microsoft.VisualStudioCode.RazorExtension /p:PackageVersion=<old-version> --interactive |
| 108 | + ``` |
| 109 | +3. Extract the commit SHA from the nuspec file: |
| 110 | + ```powershell |
| 111 | + Get-Content "C:\Users\<username>\source\repos\vscode-csharp\out\.nuget\microsoft.visualstudiocode.razorextension\<old-version>\microsoft.visualstudiocode.razorextension.nuspec" | Select-String -Pattern "commit" |
| 112 | + ``` |
| 113 | + This will show output like: |
| 114 | + ``` |
| 115 | + <repository type="git" url="https://github.com/dotnet/razor" branch="main" commit="b13d3cc91216d84453559c1fa6c723528195f58a" /> |
| 116 | + ``` |
| 117 | + |
| 118 | +**Note**: NuGet package names are always lower case in the `.nuget` folder, so use `microsoft.visualstudiocode.razorextension` (all lowercase) in the path. |
| 119 | + |
| 120 | +### Step 6: Get the New Razor Commit SHA |
| 121 | + |
| 122 | +After running `gulp updateRazorVersion`, the new version's package is already cached. Extract the commit SHA: |
| 123 | + |
| 124 | +```powershell |
| 125 | +Get-Content "C:\Users\<username>\source\repos\vscode-csharp\out\.nuget\microsoft.visualstudiocode.razorextension\<new-version>\microsoft.visualstudiocode.razorextension.nuspec" | Select-String -Pattern "commit" |
| 126 | +``` |
| 127 | + |
| 128 | +**Note**: The Azure DevOps artifacts feed web pages require authentication and may not load properly in automated scenarios. Always use the nuspec files from the local package cache. |
| 129 | + |
| 130 | +### Step 7: Generate Changelog Entries Using PR Finder |
| 131 | + |
| 132 | +First, locate the local `dotnet/razor` repository. Common locations include: |
| 133 | +- `C:\Users\<username>\source\repos\razor` |
| 134 | +- `C:\repos\razor` |
| 135 | + |
| 136 | +Navigate to the razor repository, fetch the latest, and run the pr-finder tool: |
| 137 | + |
| 138 | +```powershell |
| 139 | +cd <path-to-razor-repo> |
| 140 | +git fetch origin |
| 141 | +roslyn-tools pr-finder --start <old-commit-sha> --end <new-commit-sha> --format "o#" |
| 142 | +``` |
| 143 | + |
| 144 | +**Important**: The tool is invoked as `roslyn-tools` (a global tool), NOT `dotnet roslyn-tools`. |
| 145 | + |
| 146 | +This will output a list of PRs in the format needed for the changelog: |
| 147 | +``` |
| 148 | + * <PR title> (PR: [#<number>](https://github.com/dotnet/razor/pull/<number>)) |
| 149 | +``` |
| 150 | + |
| 151 | +### Step 8: Update CHANGELOG.md |
| 152 | + |
| 153 | +Add an entry to `CHANGELOG.md` under the current version section (e.g., `# 2.121.x`): |
| 154 | +Copy the results from the previous step (should already be formatted correctly). |
| 155 | + |
| 156 | +```markdown |
| 157 | +* Update Razor to <new-version> (PR: [#](https://github.com/dotnet/vscode-csharp/pull/)) |
| 158 | + * <PR title 1> (PR: [#<number>](https://github.com/dotnet/razor/pull/<number>)) |
| 159 | + * <PR title 2> (PR: [#<number>](https://github.com/dotnet/razor/pull/<number>)) |
| 160 | + ... |
| 161 | +``` |
| 162 | + |
| 163 | +Note: Leave the PR number blank initially (just `[#]`) - it will be updated after the PR is created. |
| 164 | + |
| 165 | +### Step 9: Filter Changelog Entries |
| 166 | + |
| 167 | +Review the changelog entries and remove any PRs that obviously don't affect VS Code. Remove entries that are: |
| 168 | + |
| 169 | +- **Infrastructure/Build changes**: CI/CD pipelines, build scripts, Azure DevOps configurations |
| 170 | +- **Visual Studio-only changes**: Features or fixes specific to Visual Studio IDE (not VS Code) |
| 171 | +- **Test-only changes**: Test infrastructure, test fixes that don't affect production code |
| 172 | +- **Internal tooling**: Changes to internal tools not used by the language server |
| 173 | +- **Documentation-only**: README updates, internal docs (unless they document user-facing features) |
| 174 | +- **Compiler-only changes**: Changes to the Razor compiler that don't affect the language server or VS Code extension |
| 175 | + |
| 176 | +Keep entries that are: |
| 177 | +- Language server protocol (LSP) changes |
| 178 | +- Razor formatting, completion, navigation, or refactoring features |
| 179 | +- Diagnostics and code analysis improvements |
| 180 | +- Performance improvements |
| 181 | +- Bug fixes that affect language server behavior |
| 182 | +- API changes that could affect VS Code extension |
| 183 | + |
| 184 | +### Step 10: Commit and Push |
| 185 | + |
| 186 | +```powershell |
| 187 | +git add package.json CHANGELOG.md |
| 188 | +git commit -m "Bump Razor to <new-version>" |
| 189 | +git push -u origin update/razor-<version> |
| 190 | +``` |
| 191 | + |
| 192 | +### Step 11: Create Pull Request |
| 193 | + |
| 194 | +Create a pull request on GitHub: |
| 195 | +- Title: `Bump Razor to <new-version>` |
| 196 | +- Base: `main` |
| 197 | + |
| 198 | +### Step 12: Update PR Description |
| 199 | + |
| 200 | +After creating the PR, update its description with the **full raw output** from the `roslyn-tools pr-finder` command (the unfiltered version, before removing infrastructure/test entries). This provides reviewers with a complete view of all changes included in the version bump. |
| 201 | + |
| 202 | +```powershell |
| 203 | +gh pr edit <pr-number> --repo dotnet/vscode-csharp --body "<full pr-finder output>" |
| 204 | +``` |
| 205 | + |
| 206 | +The body should include the `[View Complete Diff of Changes]` link and all PR entries exactly as output by `pr-finder`. |
| 207 | + |
| 208 | +### Step 13: Update Changelog with PR Number |
| 209 | + |
| 210 | +After the PR is created, note the PR number (e.g., `#8914`), then: |
| 211 | + |
| 212 | +1. Update the CHANGELOG.md entry to include the actual PR number: |
| 213 | + ```markdown |
| 214 | + * Bump Razor to <new-version> (PR: [#8914](https://github.com/dotnet/vscode-csharp/pull/8914)) |
| 215 | + ``` |
| 216 | + |
| 217 | +2. Commit and push the update: |
| 218 | + ```powershell |
| 219 | + git add CHANGELOG.md |
| 220 | + git commit -m "Update changelog with PR number" |
| 221 | + git push |
| 222 | + ``` |
| 223 | + |
| 224 | +## Example |
| 225 | + |
| 226 | +For updating from `10.0.0-preview.26075.11` to `10.0.0-preview.26081.1`: |
| 227 | + |
| 228 | +1. Discover latest version via `az pipelines build list` (or use a provided version) |
| 229 | +2. Branch: `update/razor-10-0-0-preview-26081-1` |
| 230 | +3. package.json change: `"razor": "10.0.0-preview.26081.1"` |
| 231 | +4. Run `gulp updateRazorVersion` |
| 232 | +5. Find old commit from nuspec for version `10.0.0-preview.26075.11` |
| 233 | +6. Find new commit from nuspec for version `10.0.0-preview.26081.1` |
| 234 | +7. Run pr-finder in razor repo |
| 235 | +8. Filter changelog entries |
| 236 | +9. Update CHANGELOG.md with the output |
| 237 | +10. Create PR titled "Bump Razor to 10.0.0-preview.26081.1" |
| 238 | +11. Update PR description with full pr-finder output |
| 239 | +12. Update changelog with PR number |
| 240 | + |
| 241 | +## Reference PR |
| 242 | + |
| 243 | +See [PR #8914](https://github.com/dotnet/vscode-csharp/pull/8914) as an example of a Razor version update. |
| 244 | + |
| 245 | +## Files Modified |
| 246 | + |
| 247 | +- `package.json` - Update `defaults.razor` version |
| 248 | +- `CHANGELOG.md` - Add changelog entry with Razor PR list |
| 249 | + |
| 250 | +## Troubleshooting |
| 251 | + |
| 252 | +### Authentication Issues with gulp updateRazorVersion |
| 253 | + |
| 254 | +If you encounter authentication errors: |
| 255 | +1. Install Azure Artifacts Credential Provider |
| 256 | +2. Run the command again - it should prompt for interactive authentication |
| 257 | + |
| 258 | +### pr-finder Returns Empty Results |
| 259 | + |
| 260 | +Ensure: |
| 261 | +1. You have fetched the latest from origin in the razor repo: `git fetch origin` |
| 262 | +2. Both commit SHAs exist in your local repo |
| 263 | +3. You have authenticated with `roslyn-tools authenticate` |
| 264 | +4. You are invoking the tool correctly as `roslyn-tools pr-finder` (not `dotnet roslyn-tools`) |
| 265 | + |
| 266 | +### Finding Commit SHAs |
| 267 | + |
| 268 | +The commit SHAs are embedded in the nuspec files inside the downloaded NuGet packages: |
| 269 | + |
| 270 | +1. After running `gulp updateRazorVersion`, packages are cached in `out/.nuget/` |
| 271 | +2. To get the old version's commit, you may need to explicitly download it first: |
| 272 | + ```powershell |
| 273 | + dotnet restore "msbuild\server" /p:PackageName=Microsoft.VisualStudioCode.RazorExtension /p:PackageVersion=<old-version> --interactive |
| 274 | + ``` |
| 275 | +3. Then read the nuspec file: |
| 276 | + ```powershell |
| 277 | + Get-Content "out\.nuget\microsoft.visualstudiocode.razorextension\<version>\microsoft.visualstudiocode.razorextension.nuspec" | Select-String -Pattern "commit" |
| 278 | + ``` |
| 279 | + |
| 280 | +**Note**: The Azure DevOps artifacts feed web pages require authentication and often fail to load in automated scenarios. Always use the local nuspec files instead. |
0 commit comments