Enforce C# 8 nullability for user code.#349
Conversation
...st/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs
Show resolved
Hide resolved
pranavkm
left a comment
There was a problem hiding this comment.
Changes look ok. Is the presence of the pragma sufficient to enforce nullability when the code is marked as generated?
src/Razor/src/Microsoft.AspNetCore.Razor.Language/RazorCodeGenerationOptions.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor/RazorProjectEngineBuilderExtensions.cs
Show resolved
Hide resolved
These are changes that @jcouv is working on adding 😄 . However, as of right now, no. |
...st/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs
Show resolved
Hide resolved
.../Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.CodeGeneration.targets
Show resolved
Hide resolved
| TagHelperDescriptorBuilder.Create("TestTagHelper2", "TestAssembly2").Build(), | ||
| }; | ||
| var projectWorkspaceState = new ProjectWorkspaceState(tagHelpers); | ||
| var projectWorkspaceState = new ProjectWorkspaceState(tagHelpers, default); |
There was a problem hiding this comment.
Can we add an integration tests for the E2E of using this at build-time?
There was a problem hiding this comment.
Absolutely, this is just a design PR 😄
913ae59 to
519d67b
Compare
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor/RazorProjectEngineBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Show resolved
Hide resolved
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
| DefineConstants="$(DefineConstants)" | ||
| DelaySign="$(DelaySign)" | ||
| DisabledWarnings="$(NoWarn)" | ||
| DisableSdkPath="$(DisableSdkPath)" |
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Outdated
Show resolved
Hide resolved
519d67b to
1dbde78
Compare
| <MicrosoftCodeAnalysisCommonPackageVersion>2.11.0-beta1-final</MicrosoftCodeAnalysisCommonPackageVersion> | ||
| <MicrosoftCodeAnalysisCSharpPackageVersion>2.11.0-beta1-final</MicrosoftCodeAnalysisCSharpPackageVersion> | ||
| <MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>2.11.0-beta1-final</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion> | ||
| <MicrosoftCodeAnalysisCommonPackageVersion>3.0.0-beta4-final</MicrosoftCodeAnalysisCommonPackageVersion> |
There was a problem hiding this comment.
This is the latest publicly available Roslyn bits on NuGet. Since we now generate code that's only understood by a newer Roslyn (#nullable restore/preview) I had to update our dependency to correspond with it. Thoughts? @rynowak
| <VSIX_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>3.0.0-beta2-18612-05</VSIX_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion> | ||
| <VSIX_MicrosoftVisualStudioLanguageServicesPackageVersion>3.0.0-beta2-18612-05</VSIX_MicrosoftVisualStudioLanguageServicesPackageVersion> | ||
| <VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>3.0.0-beta2-18612-05</VSIX_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion> | ||
| <VSIX_MicrosoftCodeAnalysisPackageVersion>3.1.0-beta1-19156-03</VSIX_MicrosoftCodeAnalysisPackageVersion> |
There was a problem hiding this comment.
This is the current version that is available for the next VS release. Had to update for similar reasons to above (need a newer Roslyn to understand #nullable restore / preview)
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Show resolved
Hide resolved
...r/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets
Show resolved
Hide resolved
...r/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets
Show resolved
Hide resolved
578137d to
1add775
Compare
|
🆙 📅 out of design. |
dougbu
left a comment
There was a problem hiding this comment.
eng/Versions.props change looks fine
...src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Compilation.targets
Show resolved
Hide resolved
- Expanded the `ProjectWorkspaceStateGenerator` to extract the C# language version when building the `ProjectWorkspaceState`. This approach enables all platforms to get nullability support without any changes (as long as they support `ProjectWorkspaceState`, which they do). Also, Roslyn suggested that we avoid dealing with LangVersion directly because there are several factors that impact its "effective" value on a project when run in tooling. - Updated the `LinePragma` code generation to include `#nullable restore` and `#nullable disable` lines to allow for project restored nullability state for user code. - Added a new `RazorProjectEngineBuilderExtensions` class that adds Roslyn specific project engine modifications. In this case it allows us to set the C# language version for a project engine and configure underlying features accordingly. - Added a `SuppressNullabilityEnforcement` flag that only turns on if C# < 8 is specified. - Updated LiveShare, VS4Mac and RazorGenerate to understand CSharpLanguageVersion. - Added a single test output to show the change. #5092
8eb35c9 to
b36198e
Compare
|
Ugh, scratch that. AspNetCore looks to be stuck on a preview4 SDK that doesn't have support for "preview" Roslyn LangVersion. Justin is working on getting a new SDK but that could take some time. So our options are:
@rynowak what would you prefer? |
8b786f0 to
9f929e6
Compare
|
This good to go in? |
ProjectWorkspaceStateGeneratorto extract the C# language version when building theProjectWorkspaceState. This approach enables all platforms to get nullability support without any changes (as long as they supportProjectWorkspaceState, which they do). Also, Roslyn suggested that we avoid dealing with LangVersion directly because there are several factors that impact its "effective" value on a project when run in tooling.LinePragmacode generation to include#nullable restoreand#nullable disablelines to allow for project restored nullability state for user code.RazorProjectEngineBuilderExtensionsclass that adds Roslyn specific project engine modifications. In this case it allows us to set the C# language version for a project engine and configure underlying features accordingly.SuppressNullabilityEnforcementflag that only turns on if C# < 8 is specified.dotnet/aspnetcore#5092