手头有一个项目,使用的RazorGenerator.Mvc,使一个项目插件化,这个插件会把cshtml也编译到DLL,同时也能够把.js ,.css 资源打包进DLL中css
用了一段时间,发现RazorGenerator.Mvc适合小型项目或者开发公共模块或者插件使用很方便,可是实现插件化仍是有些麻烦的。html
后来找到了另一个插件Plugin,能够实现项目插件化,使用步骤:mvc
1.主项目引入asp.net
根据项目需求选择合适的版本,这个是asp.net.mvc >=5.1的this
2.插件项目引入url
3.插件项目建立启动类spa
public class SchoolPlugin : IPlugin {
//插件名字 public string Name { get { return "School"; } } //初始化路由规则 public void Initialize() { var route = RouteTable.Routes.MapRoute( name: this.Name, url: this.Name + "/{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, pluginName = this.Name } ); route.DataTokens["area"] = this.Name; } //卸载插件 public void Unload() { RouteTable.Routes.Remove(RouteTable.Routes[this.Name]); } }
4.手动copy插件目录:bin(类库-Controller和业务),Content(主要是css), Scripts(js),Views(视图) 等目录 其中bin是必须的..net
也能够自动copy, 生成事件的后期生成事件命令行:插件
rd /s /q $(SolutionDir)PluginMain\Plugins\School xcopy /s /y $(ProjectDir)Views $(SolutionDir)PluginMain\Plugins\School\Views\ xcopy /s /y $(ProjectDir)Content $(SolutionDir)PluginMain\Plugins\School\Content\ xcopy /s /y $(ProjectDir)Scripts $(SolutionDir)PluginMain\Plugins\School\Scripts\
5.启动主项目, 插件项目访问路径: /School/Home/Index命令行