Skip to content

UserControls are not found with the .NET 6 SDK if the AssemblyName is changed with $(MSBuildProjectName). #5683

@loop8ack

Description

@loop8ack
  • .NET Core Version: .net6.0-windows
  • .NET Core SDK Version: 6.0.100
  • Windows Version: 10.0.19043.1288
  • Visual Studio Version: 17.1.0 Preview 1.0
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Not tested
  • Is this bug related specifically to tooling in Visual Studio? In the XAML editor and during build

Problem description:
When I change the AssemblyName based on the MSBuildProjectName property, controls in the same project are no longer found. This error occurs both in the XAML editor and when building. When I change the sdk-Version (in csproj and global.json) to 5.0.400, everything works fine.
F12 (Go to definition) from XAML editor works as expected.

Actual behavior:
Build will fail with error code "MC3074"
Description: The tag 'UserControl1' does not exist in XML namespace 'clr-namespace:WpfApp1'. Line 10 Position 10.

Minimal repro:

  1. Create a new WPF project template "WPF Application"
  2. Select .NET 6.0 as target framework
  3. Create a new UserControl and use it in the MainWindow
  4. Run the project
    => This should build and start as expected
  5. Add the following line to a PropertyGroup in the csproj-file:
    <AssemblyName>test.$(MsBuildProjectName)</AssemblyName>
  6. Run the project
    => Build will fail with error code "MC3074"
    => XAML-Editor should show the same error inline
  7. Change the target framework to "net5.0-windows".
  8. Create global.json next to the sln file with the following content:
    { "sdk": { "version": "5.0.400" } }
  9. Run the project
    => This should build and start as expected

This error only occurs when MSBuild properties are used. I tested it with $(MSBuildProjectName), $(AssemblyName) and $(RootNamespace).
But if I use $(Nullable) for example, it works as expected.
If I use a fixed value (e.g. "test.project"), it also works as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions