迁移到 netstandard2.0 - CS0246:找不到“ExportAttribute”

Migration to netstandard2.0 - CS0246: 'ExportAttribute' could not be found

提问人:Aleksandr Zolotov 提问时间:10/26/2023 更新时间:10/26/2023 访问量:8

问:

当我尝试迁移到<TargetFramework>netstandard2.0</TargetFramework>

我有错误error CS0246: The type or namespace name 'ExportAttribute' could not be found (are you missing a using directive or an assembly reference?)

这里

 [Export( typeof( IViewModelRepositoryFactory ) )]
internal sealed class ViewModelRepositoryFactory : IViewModelRepositoryFactory
{
    private readonly IViewModelFactory[] _viewModelFactories;

    [ImportingConstructor]
    public ViewModelRepositoryFactory( [ImportMany] IViewModelFactory[] viewModelFactories )

如何修复它 - 看起来我需要一些 nuget 包?

在哪个nuget中,我可以找到ExportAttribute的netstandard2.0版本?

迁移 nuget-package net-standard-2.0

评论


答:

0赞 Aleksandr Zolotov 10/26/2023 #1

只需使用最新的 System.ComponentModel.Composition nuget 包

例如,将此添加到您的 CSPROJ 文件中

  <ItemGroup>
  <PackageReference Include="System.ComponentModel.Composition" Version="4.7.0" />