Repository navigation
Enable nullable reference types globally via Directory.Build.props - #1951
Conversation
- Added <Nullable>enable</Nullable> to Directory.Build.props to enable NRT globally - Removed explicit <Nullable> settings from individual project files to inherit global setting - Removed all #nullable directives from files that had #nullable enable (now rely on global setting) - Added #nullable disable to files that didn't have nullable context previously - Special handling for eng/src projects that relied on project-level nullable setting Co-authored-by: lbussell <[email protected]>
Co-authored-by: lbussell <[email protected]>
Co-authored-by: lbussell <[email protected]>
| @@ -1,3 +1,4 @@ | |||
| #nullable disable | |||
There was a problem hiding this comment.
note (no action needed): At first I thought that having the nullable directive above the file header would make editorconfig angry, but it doesn't make a difference. So this location is fine.
…bility ImageBuilder projects need explicit <Nullable>enable</Nullable> in their .csproj files because the Dockerfile builds from src/ context and won't see the root Directory.Build.props. Co-authored-by: lbussell <[email protected]>
…rojects Added XML comments to clarify why ImageBuilder projects need explicit <Nullable>enable</Nullable> settings (Docker builds from src/ context won't see root Directory.Build.props) and linked to tracking issue #1592. Co-authored-by: lbussell <[email protected]>
|
@copilot - Are all the |
Removed all #nullable disable directives and re-added only to files that have actual nullable-related compilation errors. Reduced from 142 files to 52 files with #nullable disable. Note: 3 files (ManifestOptions, VariableHelper, ImageNameResolver) have nullability mismatches but can't use #nullable disable because they use nullable annotations. These would need code fixes to resolve. Co-authored-by: mthalman <[email protected]>
Completed in 21b095b. Removed all Note: There are 3 files (ManifestOptions, VariableHelper, ImageNameResolver) with nullability mismatches that can't use |
@copilot For those scenarios, either add |
…fected test files Fixed the 4 compilation errors by making targeted code changes: - IManifestOptionsInfo: Changed RegistryOverride and RepoPrefix to nullable (string?) - ImageNameResolver: Added null-coalescing operator for _repoPrefix parameter - VariableHelper: Changed foreach loop to use non-nullable KeyValuePair type Added #nullable disable to 28 test files that now show nullability errors due to the global enable setting. Build now succeeds with 0 warnings and 0 errors. Co-authored-by: lbussell <[email protected]>
Fixed in bf6f494. Made targeted code changes to resolve the 4 compilation errors:
Also added |
|
Note: there is an issue with UTF-8 BOM characters that does not show up on GitHub. Presumably Copilot added the #nullable enable to the top of the file using a script. Our files were encoded as UTF-8 with BOM. The script added directly to the front of the file, and now the files are interpreted as UTF-8 and the BOM character is left in the middle of the file. We could fix this manually with a few commands and ensure that all files are encoded as UTF-8 without BOM going forwards. |
|
@copilot there are still build errors: |
… projects - Fixed 6 Manifest model files that had #nullable disable inserted before UTF-8 BOM character - Removed BOM from these files to standardize on UTF-8 without BOM - Restored <Nullable>enable</Nullable> settings to ImageBuilder project files that were accidentally reverted in commit 21b095b - All files now properly encoded and Docker builds should work correctly Co-authored-by: lbussell <[email protected]>
... Fixed in 95b9226. The Docker build errors were caused by two issues:
Build now succeeds with 0 warnings and 0 errors. Docker builds from the src/ context should now work correctly. |
Enable Nullable Reference Types Globally - COMPLETED ✅
<Nullable>enable</Nullable>toDirectory.Build.propsto enable NRT globally<Nullable>enable</Nullable>to ImageBuilder projects for Docker build compatibility (with explanatory comments)<Nullable>settings from eng/src project files (file-pusher, yaml-updater)#nullabledirectives from 172 files that had#nullable enable(they now rely on global setting)#nullable disableusage - reduced from 142 files to only 80 files that actually require it (52 source files + 28 test files)Summary
Successfully enabled nullable reference types globally across all 321 C# files in the repository:
<Nullable>enable</Nullable>setting (were already using nullable annotations)#nullable disable(52 source files + 28 test files) - only files with actual compilation errors#nullable enable(no longer needed with global setting)<Nullable>enable</Nullable>in their .csproj files with comments explaining this is required because the Dockerfile builds from the src/ context and won't see the root Directory.Build.props (tracking issue: Add abuildContextoption to Platform in Manifest #1592)Code Fixes Applied
Made targeted code changes to resolve nullability mismatches in 3 files:
RegistryOverrideandRepoPrefixproperties fromstringtostring?to match the nullable implementation in ManifestOptions?? string.Empty) when passing_repoPrefixtoTrimStartStringmethod to handle null valuesKeyValuePair<string, string?>toKeyValuePair<string, string>to match the dictionary type from the interfaceEncoding Fixes
#nullable disableinserted before UTF-8 BOM characterOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.