-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Initial attempt at removing explicit #nullable enable in source #44936
base: main
Are you sure you want to change the base?
Conversation
…xing projects previously using these statements to now use <Nullable>enable</Nullable>. Got the Microsoft.DotNet.Cli.Utils.csproj building. More to come.
… nullable enable. Added WorkloadRootPath.cs since the tuples were problematic with nullability logic.
…m/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md#nullable-reference-type-support Converted Microsoft.DotNet.Configurer.csproj to nullable. Realized the other projects that need nullable are massive, so putting this on the backburner.
# Conflicts: # src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj # src/Cli/Microsoft.DotNet.Cli.Utils/UILanguageOverride.cs # src/Cli/dotnet/dotnet.csproj # src/Common/WorkloadFileBasedInstall.cs # src/Containers/Microsoft.NET.Build.Containers/LocalDaemons/DockerCli.cs # src/Resolvers/Microsoft.DotNet.NativeWrapper/Microsoft.DotNet.NativeWrapper.csproj # src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.cs # src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadInstallType.cs # src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadResolver.cs # src/Tasks/Common/NuGetUtils.cs # src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj # src/WebSdk/Publish/Tasks/MsDeploy/CommonUtility.cs # src/WebSdk/Publish/Tasks/Tasks/MsDeploy/MSDeploy.cs # src/WebSdk/Publish/Tasks/Tasks/MsDeploy/VsMsdeploy.cs # src/WebSdk/Publish/Tasks/Tasks/WebJobs/GenerateRunCommandFile.cs # src/WebSdk/Publish/Tasks/Tasks/ZipDeploy/HttpClientHelpers.cs # src/WebSdk/Publish/Tasks/Tasks/ZipDeploy/HttpResponseMessageWrapper.cs # src/WebSdk/Publish/Tasks/WebJobsCommandGenerator.cs
…ccidental removal of nullable on the WorkloadManifestReader.
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
||
namespace Microsoft.NET.Sdk.WorkloadManifestReader | ||
{ | ||
public record WorkloadRootPath(string? Path, bool Installable); |
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.
I added this record as there was a tuple being passed around previously. Made more sense to use an actual defined type.
#pragma warning disable IDE0240 // Nullable directive is redundant (when file is included to a project that already enables nullable | ||
|
||
#nullable enable | ||
|
||
|
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.
Roslyn uses some msbuild config to suppress nullable warnings on non-netcore targets. This allows running nullable analysis against only the netcore versions of core library methods like See property Possibly, dotnet/sdk may wish to do something similar. |
@RikkiGibson I'm going through and manually resolving all |
…Other minor adjustments based on PR feedback.
Another approach to consider is:
This approach has a couple of advantages:
|
Related: #25920
Summary
I started working on this in March and aborted the idea because I hit a point where thousands of changes needed to occur. There has been a resurgence in trying to get the repo to be Nullable enable everywhere.
I started by removing
#nullable enable
in any source files. Then, I attempted to make those projects use<Nullable>enable</Nullable>
. There were many issues with this, but in the end, to make the build work, any shared source files I had to add:This is because those files are now shared between both nullable and non-nullable projects. So, this is a stopgap to getting to a point where nullable is enabled everywhere and no source files contain
#nullable enable
.Problems
When making projects
<Nullable>enable</Nullable>
, there are several chain reactions that can occur.#nullable enable
in the file, or<Nullable>enable</Nullable>
null
or you need to add custom logic to handle thenull
situationnull
should be handled?
to everything is really detrimental as you can cause more work for yourself than just handlingnull
in a strategic location!
should be used sparingly and intentionally. For example,string.IsNullOrEmpty
is not recognized as a null check, so you might need to help the analyzers by putting!
on uses of the variable after that point.!
entirely. In this PR, I've converted several uses ofstring.IsNullOrEmpty
to a simple null and length check. The only reason this is required is because we build for both .NET (core) and .NET Framework. The Framework version of this method does not have the attribute that makes it aware of being a null-check. This also applies tostring.IsNullOrWhitespace
. However, my resolution for this was to just add an additional null check prior to the method call, which isn't costly.string
used as a property where you don't know ifstring.Empty
is an acceptable value?
but this can cause a chain reaction of null checking necessary throughout the class and callers of that class and its properties.Projects now using
<Nullable>enable</Nullable>
Other changes
record
to replace passing around a tuple#nullable enable
removed as all projects they were shared with became nullable-enabled projectsGoing forward
After some discussion, it seems like the forward strategy will be:
#nullable enable
at the top of every shared source file (follow-up PR)<Nullable>enable</Nullable>
to them<Nullable>enable</Nullable>
to the main Directory.Build.props, remove it from every .csproj, and remove#nullable enable
from the shared source files