Skip to content

Commit 357ce6e

Browse files
[main] Source code updates from dotnet/roslyn (#5239)
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
1 parent fb8a785 commit 357ce6e

24 files changed

Lines changed: 496 additions & 132 deletions

File tree

src/roslyn/azure-pipelines.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,17 @@ stages:
259259
helixApiAccessToken: $(HelixApiAccessToken)
260260
poolParameters: ${{ parameters.windowsPool }}
261261

262-
- template: eng/pipelines/test-windows-job.yml
263-
parameters:
264-
testRunName: 'Test Windows Desktop Spanish Release 64'
265-
jobName: Test_Windows_Desktop_Spanish_Release_64
266-
testArtifactName: Transport_Artifacts_Windows_Release
267-
configuration: Release
268-
testArguments: -testDesktop -testArch x64
269-
helixQueueName: $(HelixWindowsSpanishQueueName)
270-
helixApiAccessToken: $(HelixApiAccessToken)
271-
poolParameters: ${{ parameters.windowsPool }}
262+
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
263+
- template: eng/pipelines/test-windows-job.yml
264+
parameters:
265+
testRunName: 'Test Windows Desktop Spanish Release 64'
266+
jobName: Test_Windows_Desktop_Spanish_Release_64
267+
testArtifactName: Transport_Artifacts_Windows_Release
268+
configuration: Release
269+
testArguments: -testDesktop -testArch x64
270+
helixQueueName: $(HelixWindowsSpanishQueueName)
271+
helixApiAccessToken: $(HelixApiAccessToken)
272+
poolParameters: ${{ parameters.windowsPool }}
272273

273274
- stage: Windows_Debug_CoreClr
274275
dependsOn: Windows_Debug_Build
@@ -378,15 +379,15 @@ stages:
378379
helixApiAccessToken: $(HelixApiAccessToken)
379380
poolParameters: ${{ parameters.ubuntuPool }}
380381

381-
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
382-
- template: eng/pipelines/test-unix-job-single-machine.yml
383-
parameters:
384-
testRunName: 'Test Linux Debug Single Machine'
385-
jobName: Test_Linux_Debug_Single_Machine
386-
testArtifactName: Transport_Artifacts_Unix_Debug
387-
configuration: Debug
388-
testArguments: --testCoreClr
389-
poolParameters: ${{ parameters.ubuntuPool }}
382+
- template: eng/pipelines/test-unix-job-single-machine.yml
383+
parameters:
384+
testRunName: 'Test Linux Debug Spanish Single Machine'
385+
jobName: Test_Linux_Debug_Spanish_Single_Machine
386+
testArtifactName: Transport_Artifacts_Unix_Debug
387+
configuration: Debug
388+
testArguments: --testCoreClr
389+
poolParameters: ${{ parameters.ubuntuPool }}
390+
locale: es_ES.UTF-8
390391

391392
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
392393
- stage: MacOS_Debug_CoreClr
@@ -402,7 +403,7 @@ stages:
402403
jobName: Test_macOS_Debug
403404
testArtifactName: Transport_Artifacts_macOS_Debug
404405
configuration: Debug
405-
testArguments: --testCoreClr
406+
testArguments: --testCoreClr
406407
helixQueueName: $(HelixMacOsQueueName)
407408
helixApiAccessToken: $(HelixApiAccessToken)
408409
poolParameters: ${{ parameters.ubuntuPool }}
@@ -448,7 +449,7 @@ stages:
448449
steps:
449450
- template: eng/pipelines/checkout-windows-task.yml
450451

451-
- powershell: eng/build.ps1 -configuration Release -prepareMachine -ci -restore -binaryLogName Restore.binlog
452+
- powershell: eng/build.ps1 -configuration Release -prepareMachine -ci -restore -binaryLogName Restore.binlog
452453
displayName: Restore
453454

454455
# We additionally restore during the build because the Microsoft.DotNet.Build.Tasks.Feed package only restores when we pass `-publish`. See https://github.com/dotnet/arcade/blob/37ccfd66358af6a37a0ec385ec31d1d71bdd8723/src/Microsoft.DotNet.Arcade.Sdk/tools/Tools.proj#L61-L66
@@ -491,7 +492,7 @@ stages:
491492
custom: 'run'
492493
arguments: '--file $(Build.SourcesDirectory)/eng/ensure-sources-synced.cs'
493494

494-
- powershell: eng/validate-code-formatting.ps1 -ci -rootDirectory $(Build.SourcesDirectory)\src -includeDirectories Compilers\CSharp\Portable\Generated\, Compilers\VisualBasic\Portable\Generated\, ExpressionEvaluator\VisualBasic\Source\ResultProvider\Generated\
495+
- powershell: eng/validate-code-formatting.ps1 -ci -rootDirectory $(Build.SourcesDirectory)\src -includeDirectories Compilers\CSharp\Portable\Generated\, Compilers\VisualBasic\Portable\Generated\, ExpressionEvaluator\VisualBasic\Source\ResultProvider\Generated\
495496
displayName: Validate Generated Syntax Files
496497
condition: or(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['compilerChange'], 'true'))
497498

src/roslyn/docs/contributing/Localization In Compiler Tests.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ Localization in Compiler Tests
33

44
The compiler tests are structured such that they can be run on a machine using any locale. This
55
both serves as a tool to ensure the compiler does not have any localization errors but also to
6-
ensure that developers from any locale can contribute to the project. The ability to build and
6+
ensure that developers from any locale can contribute to the project. The ability to build and
77
execute tests should not be limited to English speaking developers.
88

9-
Our infrastructure runs the compiler test suite on `es-ES` machines for both .NET Core and .NET
10-
Framework. This helps us ensure that compiler tests can be authored and executed on non-English
9+
Our infrastructure runs the compiler test suite on `es-ES` machines for both .NET Core and .NET
10+
Framework. This helps us ensure that compiler tests can be authored and executed on non-English
1111
machines without issues.
1212

1313
## How it works
14-
To ensure that our tests run on any locale there is a general approach that is followed in the vast
15-
majority of our tests.
14+
To ensure that our tests run on any locale there is a general approach that is followed in the vast
15+
majority of our tests.
1616

1717
1. All expected baselines are expressed in invariant culture. That means that say `decimal` values are expressed using `.` separators not `,`.
1818
2. All generated baselines, usually via `Console.Writeline` inside `CompileAndVerify`, must be generated such that they produce output in invariant culture.
19-
3. Diagnostic tests use the `VerifyDiagnostics` helpers using `en-US` values for the messages. The implementation of `VerifyDiagnostics` will request the diagnostic message in the `en-US` culture.
19+
3. Diagnostic tests use the `VerifyDiagnostics` helpers using `en-US` values for the messages. The implementation of `VerifyDiagnostics` will request the diagnostic message in the `en-US` culture.
2020
This helps ensure the compiler has no localization product issues by forcing a consistent culture no matter the current culture of the system.
2121

22-
The largest source of friction that developers encounter when authoring tests is passing values to
23-
`Console.WriteLine` that have locale dependent representations. For example `double` and `decimal`
24-
values.
22+
The largest source of friction that developers encounter when authoring tests is passing values to
23+
`Console.WriteLine` that have locale dependent representations. For example `double` and `decimal`
24+
values.
2525

2626
```csharp
2727
decimal d = 1.2;
@@ -38,21 +38,36 @@ decimal d = 1.2;
3838
Console.WriteLine(d.ToString(CultureInfo.InvariantCulture));
3939
```
4040

41-
This will consistently print `1.2`.
41+
This will consistently print `1.2`.
4242

4343
## Exceptions
44-
There are a few cases where it is very difficult to avoid locale dependent values. These include:
44+
There are a few cases where it is very difficult to avoid locale dependent values. These include:
4545

46-
1. When a diagnostic includes a message from a thrown exception.
46+
1. When a diagnostic includes a message from a thrown exception.
4747
2. When a diagnostic includes a message from the underlying OS.
48-
3. When a message is generated by a tool such as `msbuild`.
48+
3. When a message is generated by a tool such as `msbuild`.
4949

50-
In those cases the message is likely to be locale dependent. Tests that have these values should be
50+
In those cases the message is likely to be locale dependent. Tests that have these values should be
5151
marked is `[ConditionalFact(typeof(IsEnglishLocal))]` so they run on `en-US` machines only.
5252

5353
## Infrastructure
54-
The Spanish machines used in our infrastructure execute with `CurrentCulture` set to `es-ES` but
55-
`CurrentUICulture` set to `en-US`. This configuration means that roughly string formatting happens
56-
with `es-ES` but resource lookups happen with `en-US`. This setup doesn't fully test our code base
54+
### Windows
55+
The Spanish Windows machines used in our infrastructure execute with `CurrentCulture` set to `es-ES` but
56+
`CurrentUICulture` set to `en-US`. This configuration means that roughly string formatting happens
57+
with `es-ES` but resource lookups happen with `en-US`. This setup doesn't fully test our code base
5758
so our test infrastructure will force the `CurrentUICulture` to be `CurrentCulture` when the two
5859
differ.
60+
61+
This is done in the `TestBase` constructor, which all compiler test classes inherit from. When `CurrentUICulture` does not equal `CurrentCulture`, the constructor saves the original `CurrentUICulture`
62+
and sets `CurrentUICulture` to `CurrentCulture`. The original value is restored in `Dispose` so the
63+
change is scoped to the lifetime of each test instance. This ensures that on a Windows machine configured
64+
with `CurrentCulture = es-ES` and `CurrentUICulture = en-US`, resource string lookups also happen in
65+
`es-ES`, fully exercising the localization paths.
66+
67+
### Linux
68+
The Spanish Linux machines used in our infrastructure run on Ubuntu with the `LC_ALL` environment
69+
variable set to `es_ES.UTF-8`. On .NET running on Linux, `LC_ALL` determines both `CurrentCulture`
70+
and `CurrentUICulture`. This means that unlike the Windows configuration, both string formatting and
71+
resource lookups will use `es-ES`. Because both culture values are already
72+
the same, the test infrastructure does not need to force `CurrentUICulture` to `CurrentCulture` on
73+
these machines.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Roslyn Analyzer acquisition strategy
2+
3+
This document describes how consumers should acquire the **Microsoft.CodeAnalysis.* (Roslyn) analyzer packages** over time, and why the acquisition model changes across major versions.
4+
5+
## Goals
6+
7+
1. **Reliable analyzer execution**: analyzers should run on a compiler/host that they are compatible with.
8+
2. **Lower maintenance cost**: reduce long-term burden of supporting extremely old compiler hosts.
9+
3. **Simpler acquisition**: move from “add NuGet packages” toward “enable via MSBuild properties”, where possible.
10+
4. **Version alignment**: analyzers should be **version-matched to the compiler** that executes them.
11+
12+
---
13+
14+
## Recommended guidance
15+
16+
### If you need maximum host compatibility
17+
- Prefer **<= 3.11.0** analyzer packages built from `dotnet/roslyn-analyzer`, especially when builds must run on older compilers/hosts.
18+
19+
### If you are on modern SDKs and want the newest analyzer line
20+
- Use **5.0+** analyzer packages, ensuring your build uses the **.NET 9 SDK or higher**.
21+
22+
### Plan for the SDK-based future
23+
- Expect a transition from `PackageReference`-based acquisition to **SDK-provided analyzers** enabled by configuration properties.
24+
- Prefer central configuration (for example, `Directory.Build.props`) to ease future migration.
25+
26+
---
27+
28+
## Background and timeline
29+
30+
### Analyzer packages <= 3.11.0
31+
32+
For package versions **less than or equal to 3.11.0**:
33+
34+
- The analyzer packages were built from the **`dotnet/roslyn-analyzer`** repository.
35+
- These versions were designed to support running on **very old Roslyn compilers and compiler hosts** (for example, older Visual Studio / older SDK toolsets).
36+
- This required significant **backwards-compatibility code and testing**, increasing maintenance overhead.
37+
38+
**Implication for consumers:** these packages were broadly compatible with older toolchains, making them a good choice when analyzer execution had to work across older environments.
39+
40+
---
41+
42+
### Analyzer packages 5.0+ (post-merge into dotnet/roslyn)
43+
44+
The **`dotnet/roslyn-analyzer`** repository was merged into **`dotnet/roslyn`**. As part of that consolidation:
45+
46+
- A large amount of the special-case compatibility logic for very old hosts was **removed** to reduce maintenance burden.
47+
- The newer packages adopt a compatibility posture aligned with modern SDK/compiler shipping.
48+
49+
For the new **5.0** packages:
50+
51+
- They **require the compiler from Visual Studio 17.12/.NET 9 SDK or higher**.
52+
53+
**Implication for consumers:** using 5.0 analyzers assumes your build uses a sufficiently new compiler/SDK. If your build environment is older, these analyzers are not a supported choice.
54+
55+
---
56+
57+
## Current acquisition model (today)
58+
59+
Today, acquisition is typically done via **NuGet PackageReference**, for example:
60+
61+
- Add analyzer packages to a project (`.csproj`) or centrally in `Directory.Build.props`.
62+
- Ensure the build environment uses a compiler/SDK new enough to run that analyzer version (notably for 5.0+).
63+
64+
This model works but has downsides:
65+
66+
- Consumers must discover and choose package versions.
67+
- Version skew can happen: analyzers may be newer/older than the compiler executing them.
68+
- Upgrading analyzers can implicitly require upgrading the SDK/compiler host.
69+
70+
---
71+
72+
## Future direction: ship analyzers in the .NET SDK
73+
74+
The long-term goal is to ship these analyzer packages **in the .NET SDK**. Currently Roslyn ships their CodeStyle analyzers in the SDK. Consumers opt-in to using them via the `EnforceCodeStyleInBuild` property.
75+
76+
### Why this is better
77+
78+
When analyzers ship in the SDK:
79+
80+
- The analyzers can be **version-matched to the compiler** automatically.
81+
- The acquisition experience becomes simpler:
82+
- instead of adding `PackageReference`, you enable analyzers by setting **MSBuild properties** in your `.csproj` or `Directory.Build.props`.
83+
- The SDK can ensure the analyzer/compiler pairing is known-good, reducing compatibility surprises.
84+
85+
### What this will look like for consumers
86+
87+
Conceptually, consumers will move from:
88+
89+
- “Add analyzer packages via NuGet”
90+
91+
to:
92+
93+
- “Enable analyzers via properties”
94+
95+
configured in one of:
96+
97+
- a project file (`.csproj`)
98+
- `Directory.Build.props` (recommended for repository-wide policy)
99+
100+
*(Exact property names and final UX may evolve as the SDK integration is finalized.)*

src/roslyn/eng/Version.Details.props

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ This file should be imported by eng/Versions.props
1010
<MicrosoftCodeAnalysisAnalyzersPackageVersion>5.6.0-2.26151.2</MicrosoftCodeAnalysisAnalyzersPackageVersion>
1111
<MicrosoftCodeAnalysisAnalyzerUtilitiesPackageVersion>5.6.0-2.26151.2</MicrosoftCodeAnalysisAnalyzerUtilitiesPackageVersion>
1212
<MicrosoftNetCompilersToolsetPackageVersion>5.6.0-2.26151.2</MicrosoftNetCompilersToolsetPackageVersion>
13-
<RoslynDiagnosticsAnalyzersPackageVersion>5.6.0-2.26151.2</RoslynDiagnosticsAnalyzersPackageVersion>
1413
<!-- dotnet/dotnet dependencies -->
1514
<MicrosoftBclAsyncInterfacesPackageVersion>10.0.1</MicrosoftBclAsyncInterfacesPackageVersion>
1615
<MicrosoftExtensionsConfigurationPackageVersion>10.0.1</MicrosoftExtensionsConfigurationPackageVersion>
@@ -22,8 +21,9 @@ This file should be imported by eng/Versions.props
2221
<MicrosoftExtensionsOptionsPackageVersion>10.0.1</MicrosoftExtensionsOptionsPackageVersion>
2322
<MicrosoftExtensionsOptionsConfigurationExtensionPackageVersion>10.0.1</MicrosoftExtensionsOptionsConfigurationExtensionPackageVersion>
2423
<MicrosoftExtensionsPrimitivesPackageVersion>10.0.1</MicrosoftExtensionsPrimitivesPackageVersion>
24+
<RoslynDiagnosticsAnalyzersPackageVersion>5.6.0-2.26152.106</RoslynDiagnosticsAnalyzersPackageVersion>
2525
<SystemCollectionsImmutablePackageVersion>10.0.1</SystemCollectionsImmutablePackageVersion>
26-
<SystemCommandLinePackageVersion>3.0.0-alpha.1.26062.101</SystemCommandLinePackageVersion>
26+
<SystemCommandLinePackageVersion>3.0.0-preview.3.26152.106</SystemCommandLinePackageVersion>
2727
<SystemComponentModelCompositionPackageVersion>10.0.1</SystemComponentModelCompositionPackageVersion>
2828
<SystemCompositionPackageVersion>10.0.1</SystemCompositionPackageVersion>
2929
<SystemConfigurationConfigurationManagerPackageVersion>10.0.1</SystemConfigurationConfigurationManagerPackageVersion>
@@ -40,9 +40,9 @@ This file should be imported by eng/Versions.props
4040
<SystemThreadingTasksDataflowPackageVersion>10.0.1</SystemThreadingTasksDataflowPackageVersion>
4141
<SystemWindowsExtensionsPackageVersion>10.0.1</SystemWindowsExtensionsPackageVersion>
4242
<!-- dotnet/arcade dependencies -->
43-
<MicrosoftDotNetArcadeSdkPackageVersion>10.0.0-beta.26152.1</MicrosoftDotNetArcadeSdkPackageVersion>
44-
<MicrosoftDotNetHelixSdkPackageVersion>10.0.0-beta.26152.1</MicrosoftDotNetHelixSdkPackageVersion>
45-
<MicrosoftDotNetXliffTasksPackageVersion>10.0.0-beta.26152.1</MicrosoftDotNetXliffTasksPackageVersion>
43+
<MicrosoftDotNetArcadeSdkPackageVersion>10.0.0-beta.26153.3</MicrosoftDotNetArcadeSdkPackageVersion>
44+
<MicrosoftDotNetHelixSdkPackageVersion>10.0.0-beta.26153.3</MicrosoftDotNetHelixSdkPackageVersion>
45+
<MicrosoftDotNetXliffTasksPackageVersion>10.0.0-beta.26153.3</MicrosoftDotNetXliffTasksPackageVersion>
4646
<!-- dotnet/symreader dependencies -->
4747
<MicrosoftDiaSymReaderPackageVersion>2.0.0</MicrosoftDiaSymReaderPackageVersion>
4848
<!-- dotnet/arcade-services dependencies -->
@@ -55,7 +55,6 @@ This file should be imported by eng/Versions.props
5555
<MicrosoftCodeAnalysisAnalyzersVersion>$(MicrosoftCodeAnalysisAnalyzersPackageVersion)</MicrosoftCodeAnalysisAnalyzersVersion>
5656
<MicrosoftCodeAnalysisAnalyzerUtilitiesVersion>$(MicrosoftCodeAnalysisAnalyzerUtilitiesPackageVersion)</MicrosoftCodeAnalysisAnalyzerUtilitiesVersion>
5757
<MicrosoftNetCompilersToolsetVersion>$(MicrosoftNetCompilersToolsetPackageVersion)</MicrosoftNetCompilersToolsetVersion>
58-
<RoslynDiagnosticsAnalyzersVersion>$(RoslynDiagnosticsAnalyzersPackageVersion)</RoslynDiagnosticsAnalyzersVersion>
5958
<!-- dotnet/dotnet dependencies -->
6059
<MicrosoftBclAsyncInterfacesVersion>$(MicrosoftBclAsyncInterfacesPackageVersion)</MicrosoftBclAsyncInterfacesVersion>
6160
<MicrosoftExtensionsConfigurationVersion>$(MicrosoftExtensionsConfigurationPackageVersion)</MicrosoftExtensionsConfigurationVersion>
@@ -67,6 +66,7 @@ This file should be imported by eng/Versions.props
6766
<MicrosoftExtensionsOptionsVersion>$(MicrosoftExtensionsOptionsPackageVersion)</MicrosoftExtensionsOptionsVersion>
6867
<MicrosoftExtensionsOptionsConfigurationExtensionVersion>$(MicrosoftExtensionsOptionsConfigurationExtensionPackageVersion)</MicrosoftExtensionsOptionsConfigurationExtensionVersion>
6968
<MicrosoftExtensionsPrimitivesVersion>$(MicrosoftExtensionsPrimitivesPackageVersion)</MicrosoftExtensionsPrimitivesVersion>
69+
<RoslynDiagnosticsAnalyzersVersion>$(RoslynDiagnosticsAnalyzersPackageVersion)</RoslynDiagnosticsAnalyzersVersion>
7070
<SystemCollectionsImmutableVersion>$(SystemCollectionsImmutablePackageVersion)</SystemCollectionsImmutableVersion>
7171
<SystemCommandLineVersion>$(SystemCommandLinePackageVersion)</SystemCommandLineVersion>
7272
<SystemComponentModelCompositionVersion>$(SystemComponentModelCompositionPackageVersion)</SystemComponentModelCompositionVersion>

0 commit comments

Comments
 (0)