Skip to content

Fix EnforceExtendedAnalyzerRules Property Initialization Timing#440

Merged
rjmurillo merged 4 commits intomainfrom
copilot/fix-439
Jun 7, 2025
Merged

Fix EnforceExtendedAnalyzerRules Property Initialization Timing#440
rjmurillo merged 4 commits intomainfrom
copilot/fix-439

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 7, 2025

Summary

Resolves MSBuild property initialization timing issue with EnforceExtendedAnalyzerRules detected by .NET 9 BuildChecks. The property was being accessed by Microsoft.Managed.Core.targets before PropertyGroup evaluation completed, causing BC0202 errors.

Problem

BuildCheck reported the following error:

/usr/share/dotnet/sdk/9.0.100/Roslyn/Microsoft.Managed.Core.targets(176,9): error BC0202: 
Property: 'EnforceExtendedAnalyzerRules' first declared/initialized at 
/src/Analyzers/Moq.Analyzers.csproj (9,5) used before it was initialized.

This occurred because:

  1. EnforceExtendedAnalyzerRules was defined in individual project PropertyGroups
  2. MSBuild targets accessed the property before PropertyGroup evaluation completed
  3. The timing issue affected proper MSBuild property evaluation order

Solution

Moved EnforceExtendedAnalyzerRules property to build/targets/codeanalysis/CodeAnalysis.props with conditional targeting:

<!-- Properties for analyzer projects to resolve RS1036 -->
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'Moq.Analyzers' or '$(MSBuildProjectName)' == 'Moq.Analyzers.Test.Analyzers' or '$(MSBuildProjectName)' == 'Moq.Analyzers.Test'">
  <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

This ensures:

  • Property is available early in MSBuild evaluation (Directory.Build.props imports occur before project files)
  • Only applies to analyzer projects that need it (resolves RS1036)
  • Eliminates duplication across project files

Changes

  • Added: Conditional PropertyGroup in CodeAnalysis.props for analyzer projects
  • Removed: EnforceExtendedAnalyzerRules declarations from 3 project files
  • Impact: 4 files modified, 5 additions, 5 deletions

Verification

dotnet build /check no longer reports BC0202 errors for EnforceExtendedAnalyzerRules
✅ Main analyzer project builds successfully
✅ Property correctly applied only to analyzer projects
✅ MSBuild property evaluation timing issue resolved

Fixes #439.


💡 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

CLAassistant commented Jun 7, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ rjmurillo
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits June 7, 2025 09:14
…ion timing issue

Co-authored-by: rjmurillo <6811113+rjmurillo@users.noreply.github.com>
Co-authored-by: rjmurillo <6811113+rjmurillo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix EnforceExtendedAnalyzerRules Property Initialization Timing (Medium priority) Fix EnforceExtendedAnalyzerRules Property Initialization Timing Jun 7, 2025
Copilot AI requested a review from rjmurillo June 7, 2025 09:22
@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.

@rjmurillo rjmurillo marked this pull request as ready for review June 7, 2025 15:50
Copilot AI review requested due to automatic review settings June 7, 2025 15:50
@rjmurillo rjmurillo requested a review from MattKotsenas as a code owner June 7, 2025 15:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 resolves an MSBuild property initialization timing issue reported by .NET 9 BuildChecks by moving the EnforceExtendedAnalyzerRules property to a centralized location in CodeAnalysis.props and removing duplicate declarations from individual project files.

  • Moved EnforceExtendedAnalyzerRules property to build/targets/codeanalysis/CodeAnalysis.props with a conditional property group.
  • Removed duplicate EnforceExtendedAnalyzerRules declarations from three project files.

Reviewed Changes

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

File Description
tests/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj Removed the EnforceExtendedAnalyzerRules property to avoid early access
tests/Moq.Analyzers.Test.Analyzers/Moq.Analyzers.Test.Analyzers.csproj Removed the EnforceExtendedAnalyzerRules property to prevent duplication
src/Analyzers/Moq.Analyzers.csproj Removed the EnforceExtendedAnalyzerRules property for improved build evaluation
build/targets/codeanalysis/CodeAnalysis.props Added a conditional PropertyGroup to define EnforceExtendedAnalyzerRules early in the build process

@qlty-cloud-legacy
Copy link
Copy Markdown

Code Climate has analyzed commit 30860e1 and detected 0 issues on this pull request.

View more on Code Climate.

@codacy-production
Copy link
Copy Markdown

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 (2783b99) 876 791 90.30%
Head commit (30860e1) 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 (#440) 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

@rjmurillo rjmurillo merged commit 5e172bb into main Jun 7, 2025
12 of 13 checks passed
@rjmurillo rjmurillo deleted the copilot/fix-439 branch June 7, 2025 15:52
@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 EnforceExtendedAnalyzerRules Property Initialization Timing (Medium priority)

4 participants