Skip to content

IncludePackageReferencesDuringMarkupCompilation causes build errors with WPF projects #5576

Closed

Description

@las-nsc

The reason for enabling this setting is to include code from a source generator (BoilerPlateZero), but that wasn't needed to cause the build to break.

Version Used:
.NET 5.0-windows with C#9 with VS2019 16.11.0 Enterprise

Steps to Reproduce:

  1. Take a relatively complex solution using WPF which builds with no errors
  2. Add in Directory.Build.props or *.csproj
    a. <AssemblyName>MyProductName.$(MSBuildProjectName)</AssemblyName>
    b. <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
  3. Build project

Expected Behavior:
Should build with no errors.

Actual Behavior:
Fails to builds with errors such as:

Severity Code Description
Error CS0006 Metadata file '[ProjectDir]\bin\Debug\ref\[AssemblyName].dll' could not be found.
Error CS0006 Metadata file '[ProjectDir]\bin\Debug\[AssemblyName].dll' could not be found.
Error MC2000 Unknown build error, 'Could not find file '[ProjectDir]\obj\Debug\[AssemblyName].dll'.
Error MC3050 Cannot find the type '[CustomClass]'. Note that type names are case sensitive.
Error MC3074 The tag '[CustomClass]' does not exist in XML namespace 'clr-namespace:[Namespace]'.

NOTE: In all cases, the [ProjectDir]/[AssemblyName]is the same as the source of the error (I assume due to the iterative way WPF is built) and the [CustomClass]es which aren't found in the [Namespace]s are also within the same project.

This occurs in two separate solutions using $(MSBuildProjectName) in AssemblyName, and the only way I could get it to build was to override Directory.Build.props with an explicit AssemblyName tag in the *.csproj (not using $(MSBuildProjectName)).

I tried to make a sample solution without any private code, but for some reason it was lacking the complexity which causes it to fail, sorry.

Activity

  1. sharwell commented on Oct 20, 2021

    @sharwell
    Contributor

    @dotnet/roslyn-compiler we weren't sure if this should be transferred to dotnet/sdk or dotnet/wpf; feel free to transfer if it's not a compiler problem.

  2. transferred this issue fromdotnet/roslynon Oct 21, 2021
  3. self-assigned this
    on Oct 25, 2021
  4. transferred this issue fromdotnet/sdkon Oct 25, 2021
  5. removed their assignment
    on Oct 25, 2021
  6. ryalanms commented on Oct 25, 2021

    @ryalanms
    Member

    @vishalmsft: There are changes in 6.0 that need to be backported to 5.0.

  7. added
    Investigate
    on Oct 27, 2021
  8. vishalmsft commented on Dec 7, 2021

    @vishalmsft
    Contributor

    @ryalanms please help with providing the reference to those PR, which fixed for .NET 6.
    The issue seems to be reproducible in VS version higher than 16.11, as referenced in the issue #5711

  9. Nefarion commented on Aug 29, 2023

    @Nefarion

    I finally managed to find a relatively simple fix for this.
    My projects all reference a "base" project with <Import Project="$(ProjectDir)..\<BaseProject>.csproj" /> that sets the AssemblyName based on $(MSBuildProjectName).

    The problem is, that the WPF two stage compilation process adds <AssemblyName> overrides to the TOP of the csproj file, which gets overridden by the included BaseProject file, and since the MSBuildProjectName is a temporary project, the AssemblyName is wrong.

    The simple fix, make the AssemblyName change conditional in the BaseProject file!

    -<PropertyGroup>
    +<PropertyGroup Condition="'$(_TargetAssemblyProjectName)' == ''">
      <AssemblyName>$(MSBuildProjectName)</AssemblyName>
    </PropertyGroup>

    Works like a charm for me!

  10. Kuldeep-MS commented on Sep 7, 2023

    @Kuldeep-MS
    Contributor

    @las-nsc - Whilst I examine this more closely, would you kindly review this PR that may have resolved this issue? The PR has already been merged and can be found in the latest code. Please test it out and inform us if it resolves the issue, so we can close it. If it does not resolve the issue, I will continue working on it.

  11. added
    📭 waiting-author-feedback
    on Nov 24, 2023
  12. Kuldeep-MS commented on Nov 24, 2023

    @Kuldeep-MS
    Contributor

    @las-nsc - Can you verify whether this PR resolves the issue? If it does, we can close this issue.

  13. ghost closed this as completedon Dec 15, 2023
  14. locked and limited conversation to collaborators on Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

📭 waiting-author-feedbackInvestigate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions