Skip to content

Regression for custom AssemblyName in WPF apps #5711

Open

Description

@maciej-izak

Issue Description

The PropertyGroup item AssemblyName cannot use macros for WPF app. This is regression, all was fine for previous MSBuild version (16)

Steps to Reproduce

Add to *.csproj something like :

        <MainName>$(MSBuildProjectName.Replace('-NetCore', ''))</MainName>
        <AssemblyName>$(MainName)</AssemblyName>

Example project attached:

WpfApp1.zip

Expected Behavior

Should compile/build

Actual Behavior

Error occurs :

  MainWindow.xaml(10, 10): [MC3074] The tag 'DelayTextBox' does not exist in XML namespace 'clr-namespace:WpfApp1'. Line 10 Position 10.

When mentioned above part of *.csproj is deleted all compiles/build again...

Analysis

Important note : to reproduce, ensure that bin and obj directories are deleted.

Versions & Configurations

17.0.0.52104

Activity

  1. jrboom commented on Nov 9, 2021

    @jrboom

    I have the same issue since upgrading to VS2022.

  2. changed the title [-]Regression for AssemblyName in WPF apps[/-] [+]Regression for custom AssemblyName in WPF apps[/+] on Nov 9, 2021
  3. benvillalobos commented on Nov 11, 2021

    @benvillalobos
    Member

    Team Triage: What msbuild version did this succeed on? We can't reproduce this with 16.11.0.

  4. maciej-izak commented on Nov 11, 2021

    @maciej-izak
    Author

    @benvillalobos It was 16.9.0, but .NET 5.0 SDK on my CI system was not up to date, so I guess that 16.11.0 is also ok. With msbuild 17.0.0 I am not able to build my WPF projects for net5-windows nor net6-windows :(

  5. jrboom commented on Nov 15, 2021

    @jrboom

    I can confirm that custom assembly names with macros were still working with 16.11.0, but stopped working with 17.0.0.
    Custom assembly names without macros do work correctly with 17.0.0.

  6. benvillalobos commented on Nov 18, 2021

    @benvillalobos
    Member

    MSBuild Team Triage: We think this a WPF issue. It looks like the property AssemblyName is no longer being passed as a global property. See the picture below:

    left side is a failed build (SDK 6.0.100), right side is a successful build (SDK 5.0.403)
    image

  7. las-nsc commented on Nov 25, 2021

    @las-nsc

    This sounds very similar to an issue (#5576) I've been having with both VS 2019 and VS 2022, it was only affecting .net 5 on 2019 before but it's affecting .net 4x on 2022 now, and somehow having both installed as made the problem spread to 2019.

    My setup is slightly different, I have a Directory.Build.props file which sets
    <AssemblyName>$(Product).$(MSBuildProjectName)</AssemblyName>
    (this can be in the csproj too, makes no difference)
    But I think the end result is the same, the 2-stage compilation process isn't using the same assembly name for both stages, so when it tries to resolve types it can't find them.

    I urgently need a fix for this, because now my software won't compile without adding explicit AssemblyName overrides to all of my projects.

  8. maciej-izak commented on Nov 25, 2021

    @maciej-izak
    Author

    @las-nsc the root of the problem probably is the same. For this issue I've made minimal/simplified example. Originally I have *.props too. #5576 is for sure related, for my project I have some of mentioned errors too.

  9. las-nsc commented on Nov 25, 2021

    @las-nsc

    I had to revert back to 16.9.x to get it to compile again, 16.10.x, 16.11.x and 17.x all have the issue.

  10. las-nsc commented on Nov 25, 2021

    @las-nsc

    I believe I have found a workaround, which might reveal the answer to whomever fixes this.

    By adding:

    <AssemblyName Condition="$(_TargetAssemblyProjectName) != ''">$(Product).$(_TargetAssemblyProjectName)</AssemblyName>
    

    It corrects the assembly name from being the Temporary one generated by the WPF compilation.

    Note: this only works when IncludePackageReferencesDuringMarkupCompilation is false.

  11. vishalmsft commented on Dec 7, 2021

    @vishalmsft
    Contributor

    MSBuild Team Triage: We think this a WPF issue. It looks like the property AssemblyName is no longer being passed as a global property. See the picture below:

    left side is a failed build (SDK 6.0.100), right side is a successful build (SDK 5.0.403) image

    @benvillalobos The image that you shared, helps in identifying the root cause.
    As per the user, the issue can be observed, after upgrading the VS version.
    Few questions:

    1. Were there any changes in msbuild or prop file, defining or restricting the scope of properties or inheritance of those in child project?
    2. Looked up the changes in Microsoft.WinFX.targets, There are no changes in the tasks or parameters.
  12. las-nsc commented on Dec 7, 2021

    @las-nsc

    @vishalmsft The issue is in src\Microsoft.DotNet.Wpf\src\PresentationBuildTasks\Microsoft\Build\Tasks\Windows\GenerateTemporaryTargetAssembly.cs

    There are 2 methods which handle generating the project in this step, and which one is determined by IncludePackageReferencesDuringMarkupCompilation. Both are similar, but some build properties are set via MSBuild params and some are set by writing them to the temporary project file. Either way it doesn't work properly, but using the workaround I mentioned before does fix the issue when IncludePackageReferencesDuringMarkupCompilation is false (the old mechanism).

    Ultimately, the properties need to resolve to the same value for this temporary build as they do for the final build. In my example, that is because MSBuildProjectName is wrong because the Project name is derived from the file name, which has been changed by adding _random_wpftmp.

  13. anslmorvan commented on Dec 10, 2021

    @anslmorvan

    Do you have sort of a planning for the publication of a fix?

  14. 12 remaining items

  15. Kuldeep-MS commented on Nov 24, 2023

    @Kuldeep-MS
    Contributor

    Just to clarify - the fix for this has been merged for .NET9. Hence it will be available starting .NET9 Preview1.

  16. HermanEldering commented on Nov 24, 2023

    @HermanEldering

    @Kuldeep-MS does this also fix #2930?

    It was suggested by someone in this thread that both issues have the same cause.

  17. locked and limited conversation to collaborators on Dec 25, 2023
  18. Kuldeep-MS commented on Feb 21, 2024

    @Kuldeep-MS
    Contributor

    @Kuldeep-MS does this also fix #2930?

    It was suggested by someone in this thread that both issues have the same cause.

    @HermanEldering - No it dosen't. The fix is intended to solve the problem originally reported in this issue i.e. AssemblyName cannot use $MSBuildProjectName.

  19. ChadNedzlek commented on Jan 26, 2025

    @ChadNedzlek

    This is not fixed in .NET 9.0. I'm using the shipped version of .NET 9.0, and this still happens. If anything sets "<AssemblyName>" I can't reference any of my classes in XAML files in the project.

  20. ChadNedzlek commented on Jan 26, 2025

    @ChadNedzlek

    This is very unfortunate, because I want the name of my executable to be short, useful, and memorable. But with WPF I just can't. If I try to change the name of the assembly, nothing loads.

  21. added
    Priority:1
    on Sep 29, 2026
  22. self-assigned this
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚧 work in progressBugPR ProposedPriority:1Wave1

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions