Skip to content

Enforce #nullable enable in source packages - #85067

Merged
jjonescz merged 2 commits into
dotnet:mainfrom
jjonescz:BuildEnvironment-SourcePackage
Aug 27, 2026
Merged

Enforce #nullable enable in source packages#85067
jjonescz merged 2 commits into
dotnet:mainfrom
jjonescz:BuildEnvironment-SourcePackage

Conversation

@jjonescz

@jjonescz jjonescz commented Aug 27, 2026

Copy link
Copy Markdown
Member

Fixes build failures in dotnet/dotnet#8731

src\sdk\artifacts\.packages\microsoft.codeanalysis.buildclient\5.12.0-ci\contentFiles\cs\net10.0\IBuildEnvironment.cs(16,18): error CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.

And ensures they don't happen in the future.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings August 27, 2026 09:54
@jjonescz
jjonescz requested review from a team as code owners August 27, 2026 09:54
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Roslyn’s source-package build and packaging settings so that nullable annotations in packaged source files are always in an explicit #nullable context (per-file), preventing downstream consumers from hitting missing-nullable-context diagnostics.

Changes:

  • Skip importing PackageProject.props/targets for IsSourcePackage projects under src/NuGet so those source-package projects can build under normal SDK compilation behavior.
  • Add #nullable enable directives to the BuildClient source-packaged files that use nullable annotations.
  • Set <Nullable>disable</Nullable> for IsSourcePackage projects to require per-file #nullable directives in the packaged sources.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/NuGet/Directory.Build.targets Avoids importing PackageProject.targets for IsSourcePackage projects under src/NuGet.
src/NuGet/Directory.Build.props Avoids importing PackageProject.props for IsSourcePackage projects under src/NuGet.
src/Compilers/Shared/StandardBuildEnvironment.cs Adds #nullable enable at file scope so nullable annotations are in an explicit nullable context.
src/Compilers/Shared/IBuildEnvironment.cs Adds #nullable enable at file scope so nullable annotations are in an explicit nullable context.
eng/targets/Imports.targets Sets <Nullable>disable</Nullable> for IsSourcePackage projects to enforce per-file #nullable enabling.

Comment thread eng/targets/Imports.targets Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@jjonescz
jjonescz enabled auto-merge (squash) August 27, 2026 16:40
@jjonescz
jjonescz merged commit 731c06c into dotnet:main Aug 27, 2026
25 checks passed
@jjonescz
jjonescz deleted the BuildEnvironment-SourcePackage branch August 27, 2026 18:02
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants