获取 MC3074 标签 'AssemblyPartControl' 在 XML 命名空间 'clr-namespace:EndGrain.View' 中不存在
Getting MC3074 The tag 'AssemblyPartControl' does not exist in XML namespace 'clr-namespace:EndGrain.View'
和其他许多人一样,我看到了这个编译错误。我是一名长期开发人员,在离开多年后回到 WPF。
我有一个针对 net6.0-windows
的单一项目解决方案(下面切换到 net5.0-windows
进行测试)。该项目是在 VS 2022 Pro 中创建的。我没有在我的 clr-namespace:
声明中指定 ;assembly=
。在广泛阅读 SO 之后,我相信这两种情况是导致此错误的最常见原因。
项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>annotations</Nullable>
<UseWPF>true</UseWPF>
<AssemblyName>NTS$(MSBuildProjectName)Boards</AssemblyName>
</PropertyGroup>
</Project>
用户控件
<UserControl x:Class="EndGrain.View.AssemblyPartControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:EndGrain.View"
xmlns:vm="clr-namespace:EndGrain.ViewModel"
mc:Ignorable="d"
>
...
<Grid Background="{StaticResource BackgroundBrush}">
...
</Grid>
</UserControl>
UserControl 代码隐藏
using System.Windows.Controls;
namespace EndGrain.View
{
/// <summary>
/// Interaction logic for AssemblyPartControl.xaml
/// </summary>
public partial class AssemblyPartControl : UserControl
{
public AssemblyPartControl()
{
InitializeComponent();
}
}
}
查看
<Window x:Class="EndGrain.View.AssemblyPartSandboxView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:EndGrain.View"
mc:Ignorable="d"
Title="AssemblyPartSandboxView" Height="100" Width="200">
<Grid>
<vw:AssemblyPartControl Width="100" Height="30" />
</Grid>
</Window>
我试过的
开始于 Visual Studio Professional 2022 17.0.2
- Built the project without the UserControl. Builds fine.
- Typed in the <vw:AssemblyPartControl /> element. Built the project. Error list shows the error.
- Changing the target framework back to net5.0-windows (from net6.0-windows) does not help.
用Visual Studio2019 Enterprise 16.11.7
打开了net5项目
- Rebuilt the project. Error shows.
- Commented out the UserControl. Rebuilt. Builds fine.
- Uncommented the UserControl. Rebuilt. Error shows.
使用 Blend for Visual Studio Enterprise 2019 16.11.7
打开
- Dragged the UserControl to the design surface. Blend added the element with the vw namespace.
- Built the project, and the Error List shows the error.
在命名空间定义中添加了 ;assembly=NTSEndGrainBoards
,因为我已经覆盖了默认程序集名称。没有效果。
希望一双敏锐的眼睛能看到我犯下的愚蠢错误;不可能这么难。预先感谢您的帮助。
当我完成我的问题时,我决定尝试删除非标准程序集名称。成功了。希望这对其他人有所帮助,再次感谢您的观看。
修改后的项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>annotations</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
和其他许多人一样,我看到了这个编译错误。我是一名长期开发人员,在离开多年后回到 WPF。
我有一个针对 net6.0-windows
的单一项目解决方案(下面切换到 net5.0-windows
进行测试)。该项目是在 VS 2022 Pro 中创建的。我没有在我的 clr-namespace:
声明中指定 ;assembly=
。在广泛阅读 SO 之后,我相信这两种情况是导致此错误的最常见原因。
项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>annotations</Nullable>
<UseWPF>true</UseWPF>
<AssemblyName>NTS$(MSBuildProjectName)Boards</AssemblyName>
</PropertyGroup>
</Project>
用户控件
<UserControl x:Class="EndGrain.View.AssemblyPartControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:EndGrain.View"
xmlns:vm="clr-namespace:EndGrain.ViewModel"
mc:Ignorable="d"
>
...
<Grid Background="{StaticResource BackgroundBrush}">
...
</Grid>
</UserControl>
UserControl 代码隐藏
using System.Windows.Controls;
namespace EndGrain.View
{
/// <summary>
/// Interaction logic for AssemblyPartControl.xaml
/// </summary>
public partial class AssemblyPartControl : UserControl
{
public AssemblyPartControl()
{
InitializeComponent();
}
}
}
查看
<Window x:Class="EndGrain.View.AssemblyPartSandboxView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:EndGrain.View"
mc:Ignorable="d"
Title="AssemblyPartSandboxView" Height="100" Width="200">
<Grid>
<vw:AssemblyPartControl Width="100" Height="30" />
</Grid>
</Window>
我试过的
开始于 Visual Studio Professional 2022 17.0.2
- Built the project without the UserControl. Builds fine.
- Typed in the <vw:AssemblyPartControl /> element. Built the project. Error list shows the error.
- Changing the target framework back to net5.0-windows (from net6.0-windows) does not help.
用Visual Studio2019 Enterprise 16.11.7
打开了net5项目- Rebuilt the project. Error shows.
- Commented out the UserControl. Rebuilt. Builds fine.
- Uncommented the UserControl. Rebuilt. Error shows.
使用 Blend for Visual Studio Enterprise 2019 16.11.7
打开- Dragged the UserControl to the design surface. Blend added the element with the vw namespace.
- Built the project, and the Error List shows the error.
在命名空间定义中添加了 ;assembly=NTSEndGrainBoards
,因为我已经覆盖了默认程序集名称。没有效果。
希望一双敏锐的眼睛能看到我犯下的愚蠢错误;不可能这么难。预先感谢您的帮助。
当我完成我的问题时,我决定尝试删除非标准程序集名称。成功了。希望这对其他人有所帮助,再次感谢您的观看。
修改后的项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>annotations</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>