C# 找不到不同程序集中的ASP.NET Core ViewComponents

C# 找不到不同程序集中的ASP.NET Core ViewComponents,c#,asp.net-core-mvc,assembly-references,view-components,C#,Asp.net Core Mvc,Assembly References,View Components,我试图从不同的部件加载ViewComponent,但在主项目中,我得到以下错误 InvalidOperationException:找不到名为“Pro.ItemViewComponent”的视图组件。视图组件必须是公共非抽象类,不包含任何泛型参数,并且必须使用“ViewComponentAttribute”修饰,或者具有以“ViewComponent”后缀结尾的类名。视图组件不得使用“NonViewComponentAttribute”装饰 Library.csproj netcoreapp2

我试图从不同的部件加载ViewComponent,但在主项目中,我得到以下错误

InvalidOperationException:找不到名为“Pro.ItemViewComponent”的视图组件。视图组件必须是公共非抽象类,不包含任何泛型参数,并且必须使用“ViewComponentAttribute”修饰,或者具有以“ViewComponent”后缀结尾的类名。视图组件不得使用“NonViewComponentAttribute”装饰

Library.csproj

netcoreapp2.1
保存最新
$(包括ZorcontentinPack)
保存最新
$(包括ZorcontentinPack)
保存最新
$(包括ZorcontentinPack)
主项目中的Startup.cs。
var assembly=typeof(Pro.ItemViewComponent).assembly;
var embeddedFileProvider=新的embeddedFileProvider(
装配
“专业”
);
配置(选项=>
{
options.FileProviders.Add(embeddedFileProvider);
});

我在StackOverflow中阅读了许多文章和一些问答,但我没有找到任何解决方案,我应该怎么做才能从不同的程序集中共享ViewComponent?

在Startup.cs中的配置中问题非常简单,我必须添加
services.AddMvc().AddApplicationPart(myAssembly)完整配置如下所示

var myAssembly = typeof(MyViewComponent).Assembly;

services.AddMvc().AddApplicationPart(myAssembly);

services.Configure<RazorViewEngineOptions>(options =>
 {
       options.FileProviders.Add(new EmbeddedFileProvider(myAssembly, "ComponentLib"));          
 });
var myAssembly=typeof(MyViewComponent).Assembly;
services.AddMvc().AddApplicationPart(myAssembly);
配置(选项=>
{
添加(新的EmbeddedFileProvider(myAssembly,“ComponentLib”);
});
看一看。
var assembly = typeof(Pro.ItemViewComponent).Assembly;
var embeddedFileProvider = new EmbeddedFileProvider(
    assembly,
    "Pro"
);

services.Configure<RazorViewEngineOptions>(options =>
{
    options.FileProviders.Add(embeddedFileProvider);
});
var myAssembly = typeof(MyViewComponent).Assembly;

services.AddMvc().AddApplicationPart(myAssembly);

services.Configure<RazorViewEngineOptions>(options =>
 {
       options.FileProviders.Add(new EmbeddedFileProvider(myAssembly, "ComponentLib"));          
 });