Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ReferencePathWithRefAssemblies.Identity instead of ReferencePath.ReferenceAssembly #92

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

dfederm
Copy link
Owner

@dfederm dfederm commented Mar 27, 2024

Use ReferencePathWithRefAssemblies.Identity instead of ReferencePath.ReferenceAssembly

Related to #88.

Today we're using ReferencePath.ReferenceAssembly, which in practice is usually the correct value, but ReferencePathWithRefAssemblies is what is actually passed to the compiler in the end.

In most cases, the FindReferenceAssembliesForReferences target ends up populating ReferencePath.ReferenceAssembly if needed, and then populating ReferencePathWithRefAssemblies with ReferencePath.ReferenceAssembly:

  <Target Name="FindReferenceAssembliesForReferences"
          DependsOnTargets="ResolveReferences">
    <ItemGroup>
      <!-- Reference assemblies are not produced in all cases, but it's easier to consume them
           if this metadatum is always populated. Ensure that it points to the implementation
           assembly unless already specified. -->
      <ReferencePath Condition="'%(ReferencePath.ReferenceAssembly)' == ''">
        <ReferenceAssembly>%(FullPath)</ReferenceAssembly>
      </ReferencePath>

      <ReferencePathWithRefAssemblies Include="@(ReferencePath->'%(ReferenceAssembly)')"
                                      Condition="'$(CompileUsingReferenceAssemblies)' != 'false'">
        <OriginalPath Condition="'%(ReferencePath.Identity)' != '@(ReferencePath->'%(ReferenceAssembly)')'">%(ReferencePath.Identity)</OriginalPath>
      </ReferencePathWithRefAssemblies>
      <ReferencePathWithRefAssemblies Include="@(ReferencePath)"
                                      Condition="'$(CompileUsingReferenceAssemblies)' == 'false'" />
    </ItemGroup>
  </Target>

However, there also exists a ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies target with a comment which adds some nuance.

  <Target Name="ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies"
          BeforeTargets="CoreCompile"
          Condition="'@(ReferencePathWithRefAssemblies)' == ''">
    <!-- 
      FindReferenceAssembliesForReferences target in Common targets populate this item 
      since dev15.3. The compiler targets may be used (via NuGet package) on earlier MSBuilds. 
      If the ReferencePathWithRefAssemblies item is not populated, just use ReferencePaths 
      (implementation assemblies) as they are.
      
      Since XAML inner build runs CoreCompile directly (instead of Compile target),
      it also doesn't invoke FindReferenceAssembliesForReferences listed in CompileDependsOn.
      In that case we also populate ReferencePathWithRefAssemblies with implementation assemblies.
    -->
    <ItemGroup>
      <ReferencePathWithRefAssemblies Include="@(ReferencePath)" />
    </ItemGroup>
  </Target>

According to the comment, the generated XAML projects do not call FindReferenceAssembliesForReferences and thus ReferencePath.ReferenceAssembly won't be set. The ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies shims up the ReferencePathWithRefAssemblies item though, which is why we should be using that instead of ReferencePath.ReferenceAssembly

@dfederm dfederm force-pushed the dfederm/better-ref-assemblies branch from 57d1e3e to 5c1b9f8 Compare March 27, 2024 05:34
@dfederm dfederm merged commit 1f268f1 into main Mar 27, 2024
2 checks passed
@dfederm dfederm deleted the dfederm/better-ref-assemblies branch March 27, 2024 05:38
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