Skip to content

Fix BuildCheck property initialization timing issues (BC0202 errors)#442

Merged
rjmurillo merged 2 commits intomainfrom
copilot/fix-441
Jun 7, 2025
Merged

Fix BuildCheck property initialization timing issues (BC0202 errors)#442
rjmurillo merged 2 commits intomainfrom
copilot/fix-441

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 7, 2025

Resolves .NET 9 BuildCheck errors where properties were being used before initialization, causing BC0202 violations during dotnet build /check.

Issues Fixed

Two property initialization timing issues were identified and resolved:

  1. Description and EnforceExtendedAnalyzerRules properties in src/Analyzers/Moq.Analyzers.csproj

    • These properties were being referenced by NuGet pack targets and Roslyn analyzer targets before they were defined
    • Solution: Moved to Directory.Build.props with project-specific condition to ensure early availability
  2. ShowCommonFiles property in src/Common/Common.csproj and src/Common/Common.projitems

    • Property was defined in Common.csproj but referenced in Common.projitems before initialization
    • Solution: Added conditional default value in Common.projitems and reorganized property placement

Technical Details

The root cause was MSBuild evaluation order - SDK targets (NuGet packing, Roslyn analyzers) were importing and trying to access properties before the project files had a chance to define them. The fix ensures properties are available during the early evaluation phase by:

  • Moving critical properties to Directory.Build.props which is evaluated before individual project files
  • Adding conditional defaults in shared .projitems files to prevent undefined property access
  • Using project-specific conditions to avoid polluting other projects

Verification

  • dotnet build /check now passes with 0 errors (previously 2 BC0202 errors)
  • ✅ All regular builds continue to work correctly
  • ✅ Code formatting and pedantic builds pass
  • ✅ Changes are minimal and surgical (17 lines added, 6 removed across 4 files)

Before/After

Before:

error BC0202: Property: 'Description' first declared/initialized at .../Moq.Analyzers.csproj (20,5) used before it was initialized
error BC0202: Property: 'ShowCommonFiles' first declared/initialized at .../Common.csproj (28,5) used before it was initialized

After:

Build succeeded.
    0 Warning(s)
    0 Error(s)

Fixes #441.


💡 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.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -1,4 +1,7 @@
<Project>
<PropertyGroup>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Expected an indentation at 4 instead of at 2.

<Project>
<PropertyGroup>
<ShowCommonFiles Condition="'$(ShowCommonFiles)' == ''">false</ShowCommonFiles>
</PropertyGroup>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Expected an indentation at 4 instead of at 2.

Copilot AI changed the title [WIP] Fix Package Description Property Initialization Timing (Medium) Fix BuildCheck property initialization timing issues (BC0202 errors) Jun 7, 2025
Copilot AI requested a review from rjmurillo June 7, 2025 09:24
Co-authored-by: rjmurillo <6811113+rjmurillo@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 7, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Jun 7, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) (target: 95.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (5e172bb) 876 791 90.30%
Head commit (543ca2b) 876 (+0) 791 (+0) 90.30% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#442) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Comment thread src/Common/Common.csproj Outdated
@@ -1,4 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This was moved from a property group with a label set below but the label did not also move

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed the label placement by adding back the "Shared project settings" label when moving the properties in commit da82f9d.

Comment thread Directory.Build.props
Comment thread Directory.Build.props Outdated
Co-authored-by: rjmurillo <6811113+rjmurillo@users.noreply.github.com>
@qlty-cloud-legacy
Copy link
Copy Markdown

Code Climate has analyzed commit 543ca2b and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

View more on Code Climate.

@rjmurillo rjmurillo marked this pull request as ready for review June 7, 2025 16:28
@rjmurillo rjmurillo requested a review from MattKotsenas as a code owner June 7, 2025 16:28
@rjmurillo rjmurillo merged commit 3d6445c into main Jun 7, 2025
11 of 13 checks passed
@rjmurillo rjmurillo deleted the copilot/fix-441 branch June 7, 2025 16:57
@rjmurillo rjmurillo added this to the vNext milestone Jun 7, 2025
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.

Fix Package Description Property Initialization Timing (Medium)

3 participants