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

Enable support for C# collection expressions #1878

Open
wants to merge 40 commits into
base: staging/2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fe321c4
Create WinRTSuppressions.cs
Sergio0694 Nov 24, 2024
3d2229c
Bump Roslyn to 4.8
Sergio0694 Nov 24, 2024
ee324b5
Create CollectionExpressionSuppressor.cs
Sergio0694 Nov 24, 2024
9e78cb9
Create CollectionExpressionAnalyzer.cs
Sergio0694 Nov 24, 2024
aec1e2b
Bump Roslyn to 4.9.2
Sergio0694 Nov 24, 2024
38c9ba1
Update 'CollectionExpressionAnalyzer'
Sergio0694 Nov 24, 2024
a59e9f9
Update AotOptimizer.cs
Sergio0694 Nov 24, 2024
38075b3
Create CollectionExpressionIDE0300Suppressor.cs
Sergio0694 Nov 24, 2024
cd139de
Create CollectionExpressionIDE0305Suppressor.cs
Sergio0694 Nov 24, 2024
99d1eac
Create CollectionExpressionIDE0303Suppressor.cs
Sergio0694 Nov 24, 2024
209ef7c
Add 'SourceGeneratorTest' project
Sergio0694 Nov 24, 2024
6870388
Add tests for 'CollectionExpressionAnalyzer'
Sergio0694 Nov 24, 2024
32b440b
Fix folder for new tests
Sergio0694 Nov 24, 2024
694923c
Run new tests in CI
Sergio0694 Nov 24, 2024
827a095
Rename source generator project
Sergio0694 Nov 25, 2024
aa09f20
Use shared project for generator
Sergio0694 Nov 25, 2024
a883d78
Add shared .props for generators
Sergio0694 Nov 25, 2024
b58d93d
Add Roslyn 4.12 version of the generators
Sergio0694 Nov 25, 2024
9e90d51
Use 'Microsoft.CodeAnalysis.CSharp.Workspaces'
Sergio0694 Nov 25, 2024
002332b
Fix the diagnostic suppressors
Sergio0694 Nov 25, 2024
ca39b05
Remove leftover file
Sergio0694 Nov 25, 2024
ffaf2d2
Rename analyzer test helper
Sergio0694 Nov 25, 2024
a84a0f8
Add 'CSharpSuppressorTest<TSuppressor>' type
Sergio0694 Nov 25, 2024
0ddb2c1
Add 'DiagnosticSuppressorTests'
Sergio0694 Nov 25, 2024
056b52e
Skip new analyzers if not in 'auto' mode
Sergio0694 Nov 25, 2024
f8e9bf2
Update project references to generators
Sergio0694 Nov 25, 2024
8a14d39
Update build steps
Sergio0694 Nov 25, 2024
a89ce8a
Change analyzer rule identifier
Sergio0694 Nov 26, 2024
eec6e3d
Override resource names
Sergio0694 Nov 26, 2024
1c4db63
Only run source generator tests on x86
Sergio0694 Nov 26, 2024
ada9f66
Add 'CollectionExpressionIDE0304Suppressor'
Sergio0694 Nov 26, 2024
b71c638
Fix analyzer tests
Sergio0694 Nov 26, 2024
41f7841
Don't pack .resx files for the generators
Sergio0694 Nov 26, 2024
138be44
Handle multiple '[CollectionBuilder]' attributes
Sergio0694 Nov 26, 2024
66bac48
Enable CsWinRT options in tests
Sergio0694 Nov 26, 2024
81d8d22
Bump package and assembly versions
Sergio0694 Nov 26, 2024
b8f5c5c
Fix IDE0303, IDE0305 suppressions
Sergio0694 Dec 4, 2024
a3efe56
Fix IDE0300 suppressions
Sergio0694 Dec 4, 2024
3af932c
Fix another 'ArgumentSyntax' case
Sergio0694 Dec 4, 2024
78ef22d
Remove diagnostic suppressors
Sergio0694 Dec 5, 2024
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
17 changes: 14 additions & 3 deletions build/AzurePipelineTemplates/CsWinRT-Build-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,27 @@ steps:
WinRT.Runtime.pdb
TargetFolder: $(Build.ArtifactStagingDirectory)\release_netstandard2.0\

# Stage Source Generator
# Stage Source Generator (Roslyn 4.8)
- task: CopyFiles@2
displayName: Stage Source Generator
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
inputs:
SourceFolder: $(Build.SourcesDirectory)\src\Authoring\WinRT.SourceGenerator\bin\$(BuildConfiguration)\netstandard2.0
SourceFolder: $(Build.SourcesDirectory)\src\Authoring\WinRT.SourceGenerator.Roslyn4080\bin\$(BuildConfiguration)\netstandard2.0
Contents: |
WinRT.SourceGenerator.dll
WinRT.SourceGenerator.pdb
TargetFolder: $(Build.ArtifactStagingDirectory)\release_netstandard2.0\
TargetFolder: $(Build.ArtifactStagingDirectory)\release_netstandard2.0\roslyn4080\

# Stage Source Generator (Roslyn 4.12)
- task: CopyFiles@2
displayName: Stage Source Generator
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
inputs:
SourceFolder: $(Build.SourcesDirectory)\src\Authoring\WinRT.SourceGenerator.Roslyn4120\bin\$(BuildConfiguration)\netstandard2.0
Contents: |
WinRT.SourceGenerator.dll
WinRT.SourceGenerator.pdb
TargetFolder: $(Build.ArtifactStagingDirectory)\release_netstandard2.0\roslyn4120\

# Stage Net8.0
- task: CopyFiles@2
Expand Down
10 changes: 10 additions & 0 deletions build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ stages:
arguments: --diag $(Build.ArtifactStagingDirectory)\unittest\test.log --no-build --logger xunit;LogFilePath=UNITTEST-$(Build.BuildNumber).xml /nologo /m /p:platform=$(BuildPlatform);configuration=$(BuildConfiguration);CIBuildReason=CI -- RunConfiguration.TreatNoTestsAsError=true
testRunTitle: Unit Tests

# Run Source Generator Tests
- task: DotNetCoreCLI@2
displayName: Run Source Generator Tests
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'))
inputs:
command: test
projects: 'src/Tests/SourceGeneratorTest/SourceGeneratorTest.csproj'
arguments: --diag $(Build.ArtifactStagingDirectory)\unittest\test.log --no-build --logger trx;LogFilePath=UNITTEST-$(Build.BuildNumber).trx /nologo /m /p:configuration=$(BuildConfiguration);CIBuildReason=CI -- RunConfiguration.TreatNoTestsAsError=true
testRunTitle: Unit Tests

# Run Embedded Unit Tests
- task: DotNetCoreCLI@2
displayName: Run Embedded Unit Tests
Expand Down
7 changes: 4 additions & 3 deletions build/AzurePipelineTemplates/CsWinRT-PublishToNuget-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ stages:
WinRT.Interop.winmd
netstandard2.0\WinRT.Runtime.dll
netstandard2.0\WinRT.Host.Shim.dll
netstandard2.0\WinRT.SourceGenerator.dll
netstandard2.0\roslyn4080\WinRT.SourceGenerator.dll
netstandard2.0\roslyn4120\WinRT.SourceGenerator.dll
net8.0\WinRT.Host.Shim.dll
net8.0\WinRT.Runtime.dll
release_x64\WinRT.Host.dll
Expand Down Expand Up @@ -221,7 +222,7 @@ stages:
command: pack
searchPatternPack: nuget/Microsoft.Windows.CsWinRT.nuspec
configurationToPack: Release
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\net8.0\WinRT.Runtime.dll;source_generator=$(Build.SourcesDirectory)\netstandard2.0\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\net8.0\IIDOptimizer\*.*
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\net8.0\WinRT.Runtime.dll;source_generator_roslyn4080=$(Build.SourcesDirectory)\netstandard2.0\roslyn4080\WinRT.SourceGenerator.dll;source_generator_roslyn4120=$(Build.SourcesDirectory)\netstandard2.0\roslyn4120\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\net8.0\IIDOptimizer\*.*

- task: NuGetCommand@2
displayName: NuGet pack
Expand All @@ -230,7 +231,7 @@ stages:
command: pack
searchPatternPack: nuget/Microsoft.Windows.CsWinMD.nuspec
configurationToPack: Release
buildProperties: cswinmd_nuget_version=$(NugetVersion);cswinmd_outpath=$(Build.SourcesDirectory)\net8.0\CsWinMD;source_generator=$(Build.SourcesDirectory)\netstandard2.0\WinRT.SourceGenerator.dll
buildProperties: cswinmd_nuget_version=$(NugetVersion);cswinmd_outpath=$(Build.SourcesDirectory)\net8.0\CsWinMD;source_generator_roslyn4080=$(Build.SourcesDirectory)\netstandard2.0\roslyn4080\WinRT.SourceGenerator.dll

# ESRP CodeSigning
- task: EsrpCodeSigning@5
Expand Down
4 changes: 2 additions & 2 deletions build/AzurePipelineTemplates/CsWinRT-Variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ variables:
- name: MajorVersion
value: 2
- name: MinorVersion
value: 2
value: 3
- name: PatchVersion
value: 0
- name: WinRT.Runtime.AssemblyVersion
value: '2.2.0.0'
value: '2.3.0.0'
- name: Net5.SDK.Feed
value: 'https://dotnetcli.blob.core.windows.net/dotnet'
- name: Net8.SDK.Version
Expand Down
2 changes: 1 addition & 1 deletion nuget/Microsoft.Windows.CsWinMD.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<file src="$cswinmd_outpath$\CsWinMD.runtimeconfig.json" target="tools\native"/>
<file src="$cswinmd_outpath$\Microsoft.CodeAnalysis.CSharp.dll" target="tools\native"/>
<file src="$cswinmd_outpath$\Microsoft.CodeAnalysis.dll" target="tools\native"/>
<file src="$source_generator$" target="tools\native"/>
<file src="$source_generator_roslyn4080$" target="tools\native"/>
<file src="Microsoft.Windows.CsWinMD.targets" target="build"/>

</files>
Expand Down
5 changes: 3 additions & 2 deletions nuget/Microsoft.Windows.CsWinRT.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<file src="$interop_winmd$" target="metadata"/>
<file src="readme.txt"/>
<file src="$net8_runtime$" target="lib\net8.0\"/>
<file src="$source_generator$" target="analyzers\dotnet\cs\"/>
<file src="$source_generator_roslyn4080$" target="analyzers\dotnet\cs\roslyn4.8"/>
<file src="$source_generator_roslyn4120$" target="analyzers\dotnet\cs\roslyn4.12"/>
<file src="$winrt_host_x64$" target ="hosting\x64\native"/>
<file src="$winrt_host_x86$" target ="hosting\x86\native"/>
<file src="$winrt_host_arm64$" target ="hosting\arm64\native"/>
Expand All @@ -48,8 +49,8 @@
<file src="$winrt_host_resource_x86$" target ="hosting\x86\native\en-US"/>
<file src="$winrt_host_resource_arm64$" target ="hosting\arm64\native\en-US"/>

<!-- Pack the .resx files for WinRT.Runtime for those using the embedded support -->
<file src="..\src\WinRT.Runtime\ResX\**" target ="lib\net8.0\"/>
<file src="..\src\Authoring\WinRT.SourceGenerator\ResX\**" target ="analyzers\dotnet\cs\"/>

<!-- Add the WinRT.Runtime sources to the pkg for embedded scenarios -->

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\WinRT.SourceGenerator\WinRT.SourceGenerator.props" />
<Import Project="..\WinRT.SourceGenerator\WinRT.SourceGenerator.projitems" Label="Shared" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\WinRT.SourceGenerator\WinRT.SourceGenerator.props" />
<Import Project="..\WinRT.SourceGenerator\WinRT.SourceGenerator.projitems" Label="Shared" />

</Project>
107 changes: 57 additions & 50 deletions src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
; Shipped analyzer releases
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

## Release 1.1.1

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1000 | Usage | Error | Property should have public `get` method
CsWinRT1001 | Usage | Error | Namespaces should match the assembly namespace or be child namespaces of the assembly namespace
CsWinRT1002 | Usage | Error | Namespaces cannot differ only by case
CsWinRT1003 | Usage | Error | Component must have at least on public type
CsWinRT1004 | Usage | Error | Public types cannot be generic
CsWinRT1005 | Usage | Error | Classes exposed to CsWinRT should be sealed
CsWinRT1006 | Usage | Error | Do not expose unsupported type
CsWinRT1007 | Usage | Error | Structs should contain at least one public field
CsWinRT1008 | Usage | Error | Interfaces should not inherit interfaces that are not valid in Windows Runtime
CsWinRT1009 | Usage | Error | Class should not have multiple constructors that take the same amount of parameters
CsWinRT1010 | Usage | Error | Methods should not use parameter names that conflict with generated parameter names
CsWinRT1011 | Usage | Error | Structs should not have private fields
CsWinRT1012 | Usage | Error | Structs should not have a constant field
CsWinRT1013 | Usage | Error | Structs should only contain basic types or other structs
CsWinRT1014 | Usage | Error | Types should not overload an operator
CsWinRT1015 | Usage | Error | Do not use `DefaultOverloadAttribute` more than once for a set of overloads
CsWinRT1016 | Usage | Error | Exactly one overload should be marked as DefaultOverload
CsWinRT1017 | Usage | Error | Array types should be one dimensional, not jagged
CsWinRT1018 | Usage | Error | Array types should be one dimensional
CsWinRT1020 | Usage | Error | Do not pass parameters by `ref`
CsWinRT1021 | Usage | Error | Array parameters should not be marked `InAttribute` or `OutAttribute`
CsWinRT1022 | Usage | Error | Parameters should not be marked `InAttribute` or `OutAttribute`
CsWinRT1023 | Usage | Error | Array parameters should not be marked both `ReadOnlyArrayAttribute` and `WriteOnlyArrayAttribute`
CsWinRT1024 | Usage | Error | Array parameter marked `out` should not be declared `ReadOnlyArrayAttribute`
CsWinRT1025 | Usage | Error | Array parameter should be marked either `ReadOnlyArrayAttribute` or `WriteOnlyArrayAttribute`
CsWinRT1026 | Usage | Error | Non-array parameter should not be marked `ReadOnlyArrayAttribute` or `WriteOnlyArrayAttribute`
CsWinRT1027 | Usage | Error | Class incorrectly implements an interface

## Release 2.1.0

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1028 | Usage | Warning | Class should be marked partial
CsWinRT1029 | Usage | Warning | Class implements WinRT interfaces generated using an older version of CsWinRT.

## Release 2.1.2

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1030 | Usage | Warning | Project needs to be updated with `<AllowUnsafeBlocks>true</AllowUnsafeBlocks>` to allow generic interface code generation.
; Shipped analyzer releases
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

## Release 1.1.1

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1000 | Usage | Error | Property should have public `get` method
CsWinRT1001 | Usage | Error | Namespaces should match the assembly namespace or be child namespaces of the assembly namespace
CsWinRT1002 | Usage | Error | Namespaces cannot differ only by case
CsWinRT1003 | Usage | Error | Component must have at least on public type
CsWinRT1004 | Usage | Error | Public types cannot be generic
CsWinRT1005 | Usage | Error | Classes exposed to CsWinRT should be sealed
CsWinRT1006 | Usage | Error | Do not expose unsupported type
CsWinRT1007 | Usage | Error | Structs should contain at least one public field
CsWinRT1008 | Usage | Error | Interfaces should not inherit interfaces that are not valid in Windows Runtime
CsWinRT1009 | Usage | Error | Class should not have multiple constructors that take the same amount of parameters
CsWinRT1010 | Usage | Error | Methods should not use parameter names that conflict with generated parameter names
CsWinRT1011 | Usage | Error | Structs should not have private fields
CsWinRT1012 | Usage | Error | Structs should not have a constant field
CsWinRT1013 | Usage | Error | Structs should only contain basic types or other structs
CsWinRT1014 | Usage | Error | Types should not overload an operator
CsWinRT1015 | Usage | Error | Do not use `DefaultOverloadAttribute` more than once for a set of overloads
CsWinRT1016 | Usage | Error | Exactly one overload should be marked as DefaultOverload
CsWinRT1017 | Usage | Error | Array types should be one dimensional, not jagged
CsWinRT1018 | Usage | Error | Array types should be one dimensional
CsWinRT1020 | Usage | Error | Do not pass parameters by `ref`
CsWinRT1021 | Usage | Error | Array parameters should not be marked `InAttribute` or `OutAttribute`
CsWinRT1022 | Usage | Error | Parameters should not be marked `InAttribute` or `OutAttribute`
CsWinRT1023 | Usage | Error | Array parameters should not be marked both `ReadOnlyArrayAttribute` and `WriteOnlyArrayAttribute`
CsWinRT1024 | Usage | Error | Array parameter marked `out` should not be declared `ReadOnlyArrayAttribute`
CsWinRT1025 | Usage | Error | Array parameter should be marked either `ReadOnlyArrayAttribute` or `WriteOnlyArrayAttribute`
CsWinRT1026 | Usage | Error | Non-array parameter should not be marked `ReadOnlyArrayAttribute` or `WriteOnlyArrayAttribute`
CsWinRT1027 | Usage | Error | Class incorrectly implements an interface

## Release 2.1.0

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1028 | Usage | Warning | Class should be marked partial
CsWinRT1029 | Usage | Warning | Class implements WinRT interfaces generated using an older version of CsWinRT.

## Release 2.1.2

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1030 | Usage | Warning | Project needs to be updated with `<AllowUnsafeBlocks>true</AllowUnsafeBlocks>` to allow generic interface code generation.

## Release 2.3.0

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CsWinRT1032 | Usage | Warning | Collection expressions can only be used when statically verifiable for AOT support with WinRT.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
Loading