Skip to content

Match name-only project reference identities by simple name - #157

Open
jackdemori wants to merge 1 commit into
dfederm:mainfrom
jackdemori:fix/unbuilt-project-reference-identity
Open

jackdemori wants to merge 1 commit into
dfederm:mainfrom
jackdemori:fix/unbuilt-project-reference-identity

Conversation

@jackdemori

Copy link
Copy Markdown

Summary

Follow-up to #149 and #150.

RT0002 reports every project reference as removable when a solution is opened in an editor before it has been built. After the first build, the diagnostics go away.

Why

For each project reference, #150 compares two identities of the referenced assembly:

  • the identity the build wrote to the declared references file, and
  • the identity of the assembly the code actually uses.

Before the referenced project is built, the build can only write its simple name, Dep. The assembly the code uses has the full identity, Dep, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. The two never match, so every project reference looks unused.

A design-time build of two projects, App referencing Dep, shows the identity the build writes before and after Dep is built:

before: Dep
after:  Dep, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Fix

If the declared identity has no version, compare by simple name only. If it has a version, compare the full identity as before, so the behaviour from #150 does not change.

Tests

  • UsedCompilationReferenceMatchesNameOnlyAssemblyIdentity: a used reference declared by simple name is not reported. Fails on main.
  • UnusedCompilationReferenceWithNameOnlyAssemblyIdentityStillReportsDiagnostic: with one used and one unused reference, both declared by simple name, only the unused one is reported. Fails on main.

All tests pass on macOS: 197 passed, 0 failed, 9 skipped (they need Windows).

When the referenced project has not been built yet, its resolved FusionName holds only the simple name, while the CompilationReference carries the full identity (for example Version=1.0.0.0), so RT0002 reported every used project reference in a workspace opened before a build. A declared identity without a version now matches a used assembly of the same simple name; one with a version keeps the full identity comparison.
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.

1 participant