Skip to content

[BUG] IXC Parsing csproj files does not take attribs into consideration.#436

Merged
PTKu merged 2 commits intodevfrom
435-bug-ixc-parsing-csproj-files-does-not-take-attribs-into-consideration
Aug 13, 2025
Merged

[BUG] IXC Parsing csproj files does not take attribs into consideration.#436
PTKu merged 2 commits intodevfrom
435-bug-ixc-parsing-csproj-files-does-not-take-attribs-into-consideration

Conversation

@PTKu
Copy link
Copy Markdown
Contributor

@PTKu PTKu commented Aug 13, 2025

Summary of PR #436

Title: [BUG] IXC Parsing csproj files does not take attribs into consideration.

Implements conditional-aware csproj dependency parsing (handling Condition attributes, multi-target frameworks, and property aggregation) to fix missing references.

Purpose: Fixes incorrect dependency discovery where conditional PackageReference / ProjectReference entries (with Condition attributes or within conditional ItemGroup blocks) were previously ignored. Closes issue #435.

Key Changes:

Adds a lightweight MsBuildConditionEvaluator embedded in CsProject.cs:
Collects properties from cascading Directory.Build.props plus the project’s PropertyGroup elements.
Derives TargetFramework / TargetFrameworks (falls back to netstandard2.0 if absent).
Evaluates simple Condition expressions (==, !=, And, Or) with $(Property) expansion (not a full MSBuild interpreter).
Applies condition checks to ItemGroup, PackageReference, and ProjectReference nodes.
Refactors PackageReferences(...) and ProjectReferences(...) to iterate per target framework and filter by passing conditions.
Adds debug logging for condition evaluation and guarded failure logging on bad PackageReference parsing.
Adds handling for multi-target frameworks and basic property precedence.
Test project updated:
Adds new conditional sample content (samples/conditional/**) copied to output.
Introduces / updates tests (e.g., ConditionalDependenciesTests.cs) to assert conditional dependency resolution.
Removes unused Castle.Core.Resource using.
Minor cosmetic/whitespace adjustments.
Files Changed (4 total):

CsProject.cs (major: +~300 lines; new evaluator + refactors).
ConditionalDependenciesTests.cs (new or expanded tests for conditional references).
AXSharp.CompilerTests.csproj (adds conditional sample content include).
IxProjectTests.IntegrationCs.cs (removes unused using).
Diff Stats: Approx. +413 / -21 overall (dominant additions in CsProject.cs).

Benefits:

Correctly includes/excludes dependencies based on common Condition patterns.
Supports multi-target evaluation to gather the union of conditional dependencies.
Improves resilience (try/catch around individual PackageReference parsing).
Limitations / Risks:

Condition evaluator is naïve: no support for complex MSBuild functions, property redefinitions inside conditional PropertyGroups, string operations, Exists(), etc.
Defaults netstandard2.0 if no TF specified—could mask configuration issues.
Logical parsing is simplistic (no nested parentheses beyond single outer removal; may mis-handle complex mixed AND/OR precedence).
Returns false on evaluation exceptions (could hide valid references if a condition is slightly more complex).
Review Suggestions:

Consider unit tests covering mixed And/Or with parentheses, inequality cases, multiple TargetFrameworks, and ignored conditional PropertyGroup overrides.
Validate behavior when both TargetFramework and TargetFrameworks exist (current logic prefers single TF—intended?).
Assess whether returning false on evaluation failure is too strict; maybe fallback to true with a warning?
Potential extraction of MsBuildConditionEvaluator into its own file for clarity and future extension.
Follow-Up Opportunities:

Expand condition parser (parentheses nesting, property redefinitions, common MSBuild functions).
Cache property evaluation results per project to reduce repeated parsing.
Add verbose mode toggle for debug logs.
Status: Open, 2 commits, marked ready for review, awaiting at least one approval. No labels assigned yet.

closes #435

@PTKu PTKu linked an issue Aug 13, 2025 that may be closed by this pull request
- Added `System.Text.RegularExpressions` for regex support.
- Improved readability in `MakeValidIdentifier` method.
- Updated `ProvisionProjectStructure` to collect MSBuild properties.
- Refactored `PackageReferences` and `ProjectReferences` methods for better flexibility.
- Introduced `MsBuildConditionEvaluator` for handling MSBuild conditions.
- Added unit tests in `ConditionalDependenciesTests` for condition evaluations.
- Updated test project configuration in `AXSharp.CompilerTests.csproj`.
@PTKu PTKu requested a review from kuh0005 August 13, 2025 12:10
@PTKu PTKu marked this pull request as ready for review August 13, 2025 12:10
@PTKu PTKu requested a review from TomKovac August 13, 2025 12:10
@PTKu PTKu merged commit c8385d7 into dev Aug 13, 2025
2 checks passed
@PTKu PTKu deleted the 435-bug-ixc-parsing-csproj-files-does-not-take-attribs-into-consideration branch August 13, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] IXC Parsing csproj files does not take attribs into consideration.

1 participant