-
Notifications
You must be signed in to change notification settings - Fork 191
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
Enforce C# 8 nullability for user code. #349
Conversation
...st/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -22,7 +22,7 @@ public void ProjectSnapshotHandleProxy_RoundTripsProperly() | |||
TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly").Build(), | |||
TagHelperDescriptorBuilder.Create("TestTagHelper2", "TestAssembly2").Build(), | |||
}; | |||
var projectWorkspaceState = new ProjectWorkspaceState(tagHelpers); | |||
var projectWorkspaceState = new ProjectWorkspaceState(tagHelpers, default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an integration tests for the E2E of using this at build-time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -120,6 +133,8 @@ Copyright (c) .NET Foundation. All rights reserved. | |||
DefineConstants="$(DefineConstants)" | |||
DelaySign="$(DelaySign)" | |||
DisabledWarnings="$(NoWarn)" | |||
DisableSdkPath="$(DisableSdkPath)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what this does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue.
...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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems right
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
ProjectWorkspaceStateGenerator
to 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.LinePragma
code generation to include#nullable restore
and#nullable disable
lines to allow for project restored nullability state for user code.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.SuppressNullabilityEnforcement
flag that only turns on if C# < 8 is specified.dotnet/aspnetcore#5092