首页
学习
活动
专区
圈层
工具
发布

C# dotnet 提示找不到 CompositionContainer 类的解决方法

在构建提示 Error CS0012 和 Error CS0246 说找不到 CompositionContainer 类,原因是没有引用 System.ComponentModel.Composition 库

在构建的时候有如下提示

代码语言:javascript
代码运行次数:0
复制
0>MainWindow.xaml.cs(51,59): Error CS0246: The type or namespace name 'CompositionContainer' could not be found (are you missing a using directive or an assembly reference?)
0>MainWindow.xaml.cs(51,35): Error CS0012: The type 'CompositionContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

原因是没有引用 System.ComponentModel.Composition 库,双击项目编辑 csproj 项目,添加下面代码

代码语言:javascript
代码运行次数:0
复制
    <ItemGroup>
        <Reference Include="System.ComponentModel.Composition"/>
    </ItemGroup>

要求 csproj 是 sdk 风格的,如果不是,请右击引用,添加引用,找到 System.ComponentModel.Composition 勾选


下一篇
举报
领券