主机应用程序是 ASP.NET Core MVC。主机应用程序具有
SampleController
和 Index
操作。 Index
操作在宿主项目中没有 View
文件。
结构:
- Host application
├── Controllers
│ └── SampleController
└── Views
└── Sample
我的项目中的 Razor 类库作为插件工作。它们在主机应用程序启动时动态加载。例如
SamplePlugin
项目有Views/Sample/Index.cshtml
。
结构:
- Razor class library (SamplePlugin)
└── Views
└── Sample
└── Index.cshtml
如果我在 SamplePlugin 中定义默认情况下工作的控制器。但是我想避免在插件之间复制重复的控制器。
目标:由于第三方可以有很多实现,我在主机中有使用接口服务的控制器。 Razor 类库应包含特定服务的视图文件和接口实现。
编辑:基于 https://github.com/dotnet/aspnetcore/issues/38373#issuecomment-1449717787 解决方案是从
Content
中删除
.csproj
行
csproj 中存在错误,会突然从编译中删除视图(在插件项目内)
解决方案是遵循 https://github.com/dotnet/aspnetcore/issues/38373#issuecomment-1449717787 的指南 从
Content
文件中删除 .csproj
行