Skip to content

Commit

Permalink
Merge branch 'main' into 6640-CA2225-false-positive-when-base-class-h…
Browse files Browse the repository at this point in the history
…as-method
  • Loading branch information
NewellClark committed Jul 5, 2023
2 parents ce43e8b + 4d80bf2 commit b02af8f
Show file tree
Hide file tree
Showing 493 changed files with 10,726 additions and 4,023 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# More information: https://github.com/blog/2392-introducing-code-owners

* @dotnet/roslyn-analysis

eng/SourceBuild* @dotnet/source-build-internal
9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
<NoWarn Condition="'$(Language)' == 'C#'">$(NoWarn),1573,1591,1712</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(DotNetBuildFromSource)' == 'true'">
<!-- When building in source build mode, treat this set of warnings not as errors.-->
<!-- Some crefs reference internal APIs not present in the reference package. -->
<NoWarn>$(NoWarn);CS1574;CS8602</NoWarn>
<!-- Source build reference assemblies are not correctly annotated.
https://github.com/dotnet/source-build/issues/3531 -->
<NoWarn>$(NoWarn);CS8603</NoWarn>
</PropertyGroup>

<PropertyGroup>
<!-- We generate per-project assembly attributes files, so we can safely delete them when cleaning the project -->
<TargetFrameworkMonikerAssemblyAttributesFileClean>true</TargetFrameworkMonikerAssemblyAttributesFileClean>
Expand Down
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="dotnet8-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8-transport/nuget/v3/index.json" />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
Expand Down
22 changes: 22 additions & 0 deletions docs/rules/RS1022.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## RS1022: Do not use types from Workspaces assembly in an analyzer

Diagnostic analyzer types should not use types from Workspaces assemblies. Workspaces assemblies are only available when the analyzer executes in Visual Studio IDE live analysis, but are not available during command line build. Referencing types from Workspaces assemblies will lead to runtime exception during analyzer execution in command line build.

|Item|Value|
|-|-|
|Category|MicrosoftCodeAnalysisCorrectness|
|Enabled|True|
|Severity|Warning|
|CodeFix|False|
---

> **Warning**
>
> The analysis performed by RS1022 is slow and relies on implementation details of the JIT compiler for correctness.
> Authors of compiler extensions are encouraged to use the stricter (and faster) analyzer RS1038 instead of this rule.
>
> RS1038 is enabled by default. To enable RS1022 instead, the following configuration may be added to **.globalconfig**:
>
> ```ini
> roslyn_correctness.assembly_reference_validation = relaxed
> ```
46 changes: 46 additions & 0 deletions docs/rules/RS1038.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## RS1038: Compiler extensions should be implemented in assemblies with compiler-provided references

Types which implement compiler extension points should not be declared in assemblies that contain references to assemblies which are not provided by all compilation scenarios. Doing so may cause the feature to behave unpredictably.

|Item|Value|
|-|-|
|Category|MicrosoftCodeAnalysisCorrectness|
|Enabled|True|
|Severity|Warning|
|CodeFix|False|
---

This rule helps ensure compiler extensions (e.g. analyzers and source generators) will load correctly in all compilation
scenarios. Depending on the manner in which the compiler is invoked, some assemblies may not be present during a build,
and attempting to reference them will result in exceptions that prevent the compiler extension from loading. RS1038 is
the most strict and best performing validation for this scenario.

RS1038 is enabled by default unless relaxed validation has been manually enabled in **.globalconfig** as described in
[RS1022](RS1022.md).

### Rules for compiler feature references

* Compiler features supporting C# code should only reference the NuGet packages **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.CSharp**
* Compiler features supporting Visual Basic code should only reference **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.VisualBasic**
* Compiler features supporting both C# and Visual Basic should only reference **Microsoft.CodeAnalysis.Common**
* Compiler features should not be implemented in assemblies containing a reference to **Microsoft.CodeAnalysis.Workspaces.Common**

> **Note**
>
> This analyzer only checks references to the core Roslyn assemblies. Compiler extensions with other dependencies may
> face restrictions and/or packaging requirements outside the scope of this analyzer.
### Compiler extension points

The following compiler extension points are examined by this analyzer:

* `DiagnosticAnalyzer`
* `DiagnosticSuppressor`
* `ISourceGenerator`
* `IIncrementalGenerator`

### Other extension points

Some extension points provided by Roslyn are IDE extensions (e.g. code fixes and completion providers). These features
may ship in the same package as compiler features, but should be implemented in their own assembly since they require a
reference to non-compiler package **Microsoft.CodeAnalysis.Workspaces.Common**.
3 changes: 2 additions & 1 deletion eng/SourceBuild.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!-- Whenever altering this or other Source Build files, please include @dotnet/source-build-internal as a reviewer. -->

<Project>

<PropertyGroup>
<GitHubRepositoryName>roslyn-analyzers</GitHubRepositoryName>
<SourceBuildManagedOnly>true</SourceBuildManagedOnly>
<SourceBuildTrimNetFrameworkTargets>true</SourceBuildTrimNetFrameworkTargets>
</PropertyGroup>

</Project>
17 changes: 15 additions & 2 deletions eng/SourceBuildPrebuiltBaseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<!-- Whenever altering this or other Source Build files, please include @dotnet/source-build-internal as a reviewer. -->
<!-- See aka.ms/dotnet/prebuilts for guidance on what pre-builts are and how to eliminate them. -->

<UsageData>
<IgnorePatterns>
<UsagePattern IdentityGlob="*/*" />
<UsagePattern IdentityGlob="Microsoft.SourceBuild.Intermediate.*" />

<!-- This packages contain functionality that is executed in the build -->
<UsagePattern IdentityGlob="Microsoft.Net.Compilers.Toolset/*" />
<UsagePattern IdentityGlob="System.Composition*/*" />

<!-- This is the version of Microsoft.CodeAnalysis used for tooling executed in repo source-build,
as well as unit tests. -->
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis*/*4.6.0-1.final*" />
<!-- Dependency of Microsoft.CodeAnalysis.Common 4.6.0-1.final -->
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis.Analyzers/*3.3.4*" />
</IgnorePatterns>
</UsageData>
</UsageData>
39 changes: 28 additions & 11 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.CodeAnalysis" Version="3.3.1">
<Dependency Name="Microsoft.CodeAnalysis" Version="3.11.0">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>66a912c9463eebe832cf742d2fe8bb2e1a4600ec</Sha>
<Sha>ae1fff344d46976624e68ae17164e0607ab68b10</Sha>
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="8.0.0-alpha.1.23330.2">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>c7e229b7e8cd71c8479e236ae1efff3ad1d740f9</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="8.0.0-alpha.1.23214.1">
<Uri>https://github.com/dotnet/source-build-externals</Uri>
<Sha>de4dda48d0cf31e13182bc24107b2246c61ed483</Sha>
<SourceBuild RepoName="source-build-externals" ManagedOnly="true" />
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23269.1">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23353.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>fb6291b40fa4334dbd167e2071953e83cc8b9fdc</Sha>
<Sha>e4bd767159fde419b50dd54c6d83e1ef970a68d0</Sha>
<SourceBuild RepoName="arcade" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.5.0">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>6a5a63bbc9f4449d9bd1e95a8f9624939c3ccdc3</Sha>
<!-- Used in repo tooling. Not updated automatically -->
<Dependency Name="System.Composition" Version="8.0.0-preview.4.23259.5">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>84a3d0e37e8f22b0b55f8bf932cb788b2bdd728f</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.5.0">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>6a5a63bbc9f4449d9bd1e95a8f9624939c3ccdc3</Sha>
<Dependency Name="Microsoft.SourceLink.GitHub" Version="8.0.0-beta.23330.1" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
<Uri>https://github.com/dotnet/sourcelink</Uri>
<Sha>2cbc0223f1ea879a8ca3a5c744da52d57d6c1fcd</Sha>
<SourceBuild RepoName="sourcelink" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="4.5.0">
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="1.0.0-beta.23326.1" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
<Uri>https://github.com/dotnet/xliff-tasks</Uri>
<Sha>10a822a79bde97ca45faa76dc4ec33b85533728a</Sha>
<SourceBuild RepoName="xliff-tasks" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.5.0">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>6a5a63bbc9f4449d9bd1e95a8f9624939c3ccdc3</Sha>
</Dependency>
Expand Down
84 changes: 59 additions & 25 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<Project>
<Import Project="$(SourceBuildPackageVersionPropsPath)" Condition="'$(SourceBuildPackageVersionPropsPath)' != ''" />
<PropertyGroup>
<!--
Binaries that need to be executable during source build are restricted to versions available within source build.
This section defines executable versions of packages which are referenced via lower-version reference assemblies
during the build.
-->
<SystemCollectionsImmutableExecutableVersion>$(SystemCollectionsImmutableVersion)</SystemCollectionsImmutableExecutableVersion>
<SystemCollectionsImmutableExecutableVersion Condition="'$(SystemCollectionsImmutableExecutableVersion)' == ''">5.0.0</SystemCollectionsImmutableExecutableVersion>
<SystemReflectionMetadataExecutableVersion>$(SystemReflectionMetadataVersion)</SystemReflectionMetadataExecutableVersion>
<SystemReflectionMetadataExecutableVersion Condition="'$(SystemReflectionMetadataExecutableVersion)' == ''">5.0.0</SystemReflectionMetadataExecutableVersion>
<MicrosoftCodeAnalysisExecutableVersion>$(MicrosoftCodeAnalysisVersion)</MicrosoftCodeAnalysisExecutableVersion>
<MicrosoftCodeAnalysisExecutableVersion Condition="'$(MicrosoftCodeAnalysisExecutableVersion)' == ''">3.8.0</MicrosoftCodeAnalysisExecutableVersion>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>3.3.5</VersionPrefix>
<VersionPrefix>3.11.0</VersionPrefix>
<PreReleaseVersionLabel>beta1</PreReleaseVersionLabel>
<NetAnalyzersVersionPrefix>8.0.0</NetAnalyzersVersionPrefix>
<NetAnalyzersPreReleaseVersionLabel>preview</NetAnalyzersPreReleaseVersionLabel>
<AnalyzerUtilitiesVersionPrefix>$(VersionPrefix)</AnalyzerUtilitiesVersionPrefix>
<MetricsVersionPrefix>4.0.0</MetricsVersionPrefix>
<!--
When StabilizePackageVersion is set to 'true', this branch will produce stable outputs for 'Shipping' packages
-->
Expand All @@ -39,13 +27,59 @@
<!-- Use the correct compiler version -->
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
<!-- Dependencies from https://github.com/dotnet/roslyn -->
<MicrosoftNetCompilersToolsetVersion>4.5.0</MicrosoftNetCompilersToolsetVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.5.0</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>4.5.0</MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>
<!-- Roslyn -->
<MicrosoftCodeAnalysisVersion>3.3.1</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisForRoslynDiagnosticsAnalyzersVersion>3.7.0</MicrosoftCodeAnalysisForRoslynDiagnosticsAnalyzersVersion>
<MicrosoftCodeAnalysisVersionForTests>4.6.0-1.final</MicrosoftCodeAnalysisVersionForTests>
<MicrosoftNetCompilersToolsetVersion>4.6.0</MicrosoftNetCompilersToolsetVersion>
<!-- Microsoft.CodeAnalysis.* versions. Read this!
This repo uses a wide variety of M.CA.* package versions. This is an atypical pattern in
.NET's repositories but a necessary one for roslyn-analyzers.
Some facts:
- These versions are chosen on purpose.
- They often represent the base required surface area of Microsoft.CA to support for a given feature or analyzer.
This means that the analyzer would be supported in the widest array of C# compilation scenarios.
- Most of these dependencies only represent target surface area. In some cases, the M.CA libraries are
redistributed (tools) or used within the build.
- Some of these versions are used for testing to ensure that analyzers built against older surface area
still work against new implementations.
- Linux source-build only builds a single implementation of M.CA.*.
- Linux source-build does have some ability to provide surface area packages via the source-build-reference-packages repo.
However, because these reference packages do not provide implementations, they cannot be used in any case
where the package contents would be redisted or executed. An SBRP may not be created for a version that is used both
as a reference assembly and redisted.
In this repo, the MicrosoftCodeAnalysis property should **not** be set globally in this file. Instead, it should
be set for each project, based on the properties below. When the project is executable, it should be
set only for non-source build or repo-source build. Product source build will set an incoming MicrosoftCodeAnalysis property
that will denote the available implementation version.
Example of surface area usage:
<MicrosoftCodeAnalysisVersion>$(MicrosoftCodeAnalysisVersionForPerfSensitiveAnalyzers)</MicrosoftCodeAnalysisVersion>
Example of executable usage:
<MicrosoftCodeAnalysisVersion Condition="'$(DotNetBuildFromSource)' != 'true' or '$(DotNetBuildFromSourceFlavor)' != 'Product'">$(MicrosoftCodeAnalysisVersionForExecution)</MicrosoftCodeAnalysisVersion>
-->
<!-- Microsoft.CodeAnalysis versions for different purposes. -->
<!-- Surface area that various projects compile against. These should have source-build reference packages -->
<MicrosoftCodeAnalysisForRoslynDiagnosticsAnalyzersVersion>3.11.0</MicrosoftCodeAnalysisForRoslynDiagnosticsAnalyzersVersion>
<MicrosoftCodeAnalysisVersionForPublicApiAnalyzers>1.2.1</MicrosoftCodeAnalysisVersionForPublicApiAnalyzers>
<MicrosoftCodeAnalysisVersionForBannedApiAnalyzers>3.11.0</MicrosoftCodeAnalysisVersionForBannedApiAnalyzers>
<MicrosoftCodeAnalysisVersionForBannedApiAnalyzersTests>3.11.0</MicrosoftCodeAnalysisVersionForBannedApiAnalyzersTests>
<MicrosoftCodeAnalysisVersionForPerfSensitiveAnalyzers>3.11.0</MicrosoftCodeAnalysisVersionForPerfSensitiveAnalyzers>
<MicrosoftCodeAnalysisVersionForPerfSensitiveAnalyzersTests>3.11.0</MicrosoftCodeAnalysisVersionForPerfSensitiveAnalyzersTests>
<MicrosoftCodeAnalysisVersionForResxSourceGenerators>4.0.1</MicrosoftCodeAnalysisVersionForResxSourceGenerators>
<MicrosoftCodeAnalysisVersionForNetAnalyzers>3.11.0</MicrosoftCodeAnalysisVersionForNetAnalyzers>
<MicrosoftCodeAnalysisVersionForTextAnalyzers>3.11.0</MicrosoftCodeAnalysisVersionForTextAnalyzers>
<MicrosoftCodeAnalysisVersionForCodeAnalysisAnalyzers>3.11.0</MicrosoftCodeAnalysisVersionForCodeAnalysisAnalyzers>
<MicrosoftCodeAnalysisVersionForToolsAndUtilities>3.11.0</MicrosoftCodeAnalysisVersionForToolsAndUtilities>
<MicrosoftCodeAnalysisVersionForMetrics>4.0.1</MicrosoftCodeAnalysisVersionForMetrics>
<!-- Versions for tests and general utility execution. -->
<!-- This version is for utility and executable assemblies. The version here should not overlap with any of the surface
area versions. -->
<MicrosoftCodeAnalysisVersionForTests>4.7.0-3.23280.3</MicrosoftCodeAnalysisVersionForTests>
<MicrosoftCodeAnalysisVersionForExecution>4.6.0-1.final</MicrosoftCodeAnalysisVersionForExecution>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.6.0</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>4.6.0</MicrosoftCodeAnalysisVisualBasicCodeStyleVersion>
<DogfoodAnalyzersVersion>3.3.4</DogfoodAnalyzersVersion>
<DogfoodNetAnalyzersVersion>8.0.0-preview1.22621.6</DogfoodNetAnalyzersVersion>
<MicrosoftCodeAnalysisBannedApiAnalyzersVersion>$(DogfoodAnalyzersVersion)</MicrosoftCodeAnalysisBannedApiAnalyzersVersion>
Expand All @@ -56,11 +90,11 @@
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.0-pre-20160714</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftVisualStudioThreadingAnalyzersVersion>17.0.26-alpha</MicrosoftVisualStudioThreadingAnalyzersVersion>
<!-- Roslyn Testing -->
<MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.23205.1</MicrosoftCodeAnalysisTestingVersion>
<MicrosoftCodeAnalysisTestingVersion>1.1.2-beta1.23322.1</MicrosoftCodeAnalysisTestingVersion>
<!-- Libs -->
<BenchmarkDotNetVersion>0.13.0</BenchmarkDotNetVersion>
<HumanizerVersion>2.2.0</HumanizerVersion>
<MicrosoftBuildLocatorVersion>1.4.1</MicrosoftBuildLocatorVersion>
<HumanizerVersion>2.14.1</HumanizerVersion>
<MicrosoftBuildLocatorVersion>1.5.5</MicrosoftBuildLocatorVersion>
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.69</MicrosoftDiagnosticsTracingTraceEventVersion>
<MicrosoftExtensionsLoggingVersion>6.0.0-preview.5.21301.5</MicrosoftExtensionsLoggingVersion>
<MicrosoftNETCoreAppRefVersion>6.0.2</MicrosoftNETCoreAppRefVersion>
Expand All @@ -72,7 +106,7 @@
<SystemCommandLineRenderingVersion>2.0.0-beta1.20074.1</SystemCommandLineRenderingVersion>
<SystemCommandLineVersion>2.0.0-beta1.21216.1</SystemCommandLineVersion>
<SystemComponentModelCompositionVersion>4.7.0</SystemComponentModelCompositionVersion>
<SystemDirectoryServicesVersion>4.7.0</SystemDirectoryServicesVersion>
<SystemCompositionVersion>8.0.0-preview.4.23259.5</SystemCompositionVersion>
<XunitCombinatorialVersion>1.2.7</XunitCombinatorialVersion>
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions eng/common/dotnet-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ cpuname=$(uname -m)
case $cpuname in
arm64|aarch64)
buildarch=arm64
if [ "$(getconf LONG_BIT)" -lt 64 ]; then
# This is 32-bit OS running on 64-bit CPU (for example Raspberry Pi OS)
buildarch=arm
fi
;;
loongarch64)
buildarch=loongarch64
Expand Down
2 changes: 1 addition & 1 deletion eng/common/sdk-task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ try {
$GlobalJson.tools | Add-Member -Name "vs" -Value (ConvertFrom-Json "{ `"version`": `"16.5`" }") -MemberType NoteProperty
}
if( -not ($GlobalJson.tools.PSObject.Properties.Name -match "xcopy-msbuild" )) {
$GlobalJson.tools | Add-Member -Name "xcopy-msbuild" -Value "17.4.1" -MemberType NoteProperty
$GlobalJson.tools | Add-Member -Name "xcopy-msbuild" -Value "17.6.0-2" -MemberType NoteProperty
}
if ($GlobalJson.tools."xcopy-msbuild".Trim() -ine "none") {
$xcopyMSBuildToolsFolder = InitializeXCopyMSBuild $GlobalJson.tools."xcopy-msbuild" -install $true
Expand Down

0 comments on commit b02af8f

Please sign in to comment.