asp.net-core – 有没有办法将ASP.NET Core应用程序区域打包为Nu
我正在开发一个ASP.NET Core应用程序,我希望将其作为NuGet包发布,您可以将其添加到任何Core Web项目中.该应用程序实际上完全局限于项目中的一个区域(即/ Areas / MyArea),包括控制器,视图,服务类,模型,视图等,除了少数部分.真的,这些是我喜欢神奇地添加到现有网络应用程序的部分:
>该地区及其中的一切 我知道NuGet会恢复软件包依赖关系,但我不确定它是如何考虑客户端软件包的. 有什么建议? NuGet是错误的工具吗? 解决方法
目前afaik无法从nuget包中将文件传送到Web应用程序.我认为有一些讨论和工作正在进行中,以便将来实现这一目标.
我在我的项目中处理它的方式是嵌入视图和所需的静态js和css资源,这在project.json中是这样完成的: “buildOptions”:{ 我创建了一个controller to serve my static resources: public class cscsrController : Controller { private ContentResult GetContentResult(string resourceName,string contentType) { var assembly = typeof(cscsrController).GetTypeInfo().Assembly; var resourceStream = assembly.GetManifestResourceStream(resourceName); string payload; using (var reader = new StreamReader(resourceStream,Encoding.UTF8)) { payload = reader.ReadToEnd(); } return new ContentResult { ContentType = contentType,Content = payload,StatusCode = 200 }; } [HttpGet] [AllowAnonymous] public ContentResult bootstrapdatetimepickercss() { return GetContentResult( "cloudscribe.Core.Web.css.bootstrap-datetimepicker.min.css","text/css"); } [HttpGet] [AllowAnonymous] public ContentResult momentwithlocalesjs() { return GetContentResult( "cloudscribe.Core.Web.js.moment-with-locales.min.js","text/javascript"); } } 然后我链接到我需要加载js和/或css的视图中的控制器操作. 为了使嵌入的视图工作,我创建了一个RazorViewEngineOptions的扩展方法: public static RazorViewEngineOptions AddEmbeddedViewsForCloudscribeCore(this RazorViewEngineOptions options) { options.FileProviders.Add(new EmbeddedFileProvider( typeof(SiteManager).GetTypeInfo().Assembly,"cloudscribe.Core.Web" )); return options; } 这必须从Web应用程序Startup中的ConfigureServices调用,如下所示: services.AddMvc() .AddRazorOptions(options => { options.AddEmbeddedViewsForCloudscribeCore(); }) ; 这种技术对于区域应该是相同的.请注意,一个很酷的事情是用户可以下载视图并在本地安装它们,这将覆盖嵌入视图的使用,从而可以轻松自定义部分或全部视图.通过覆盖视图,还可以根据需要在本地手动安装js和css,如果需要自定义,则更改视图以链接到这些本地文件.最终的结果是我的nuget拥有它需要的一切,所以只有一些启动配置才能让事情发挥作用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在ASP.NET MVC表单上允许多个按钮的最佳方法是什么?
- asp.net – 无法识别的配置部分log4net. web.config网站
- asp.net-mvc-5 – 如何检查用户是否从MVC5布局文件登录
- ASP.NET – AJAX / JQUERY的重连接问题
- asp.net-mvc-3 – Windows Azure Web MVC应用程序Applicati
- asp.net – HttpCookie.Expire时区含义?
- asp.net – 使用Active Directory的REST API的授权方法
- asp.net <%$...%>语法
- asp.net-mvc – 如何建立一个ASP.NET MVC应用程序与EF?
- asp.net – 拒绝访问web.config中的“admin”文件夹
- asp.net – 是否有使用Markdown作为编辑器的WIKI
- asp.net – 在Microsoft Ajax中伪造__EVENTVALID
- asp.net-mvc – Razor查看引擎在VB.NET中的怪癖
- asp.net-mvc – 为什么我的HttpConfiguration类型
- 在Azure中设置ASP.NET 5 Web应用程序的SQL连接字
- ASP.NET应用程序未记录到Windows事件日志
- asp.net-mvc – 我可以从Model类(而不是控制器)添
- asp.net – MVC动态页权限使用授权属性?
- asp.net-mvc – 查找单元测试方向,显示部分视图的
- asp.net-core-mvc – Identity 3.0当id为“int”