Embedded Resource Files
Create embedded files
We want to make these files usable in a web application. First, we should make build action to embedded resource for files we want to expose. I select metronic.js file, go to properties window (F4 as shortcut) and change it.
You should change build action to embedded resource for all files you want to use in a web application.
Expose embedded files
ASP.NET Boilerplate makes it easy to expose embedded resource files. It's a single line of code:
WebResourceHelper.ExposeEmbeddedResources("AbpZero/Metronic", Assembly.GetExecutingAssembly(), "Abp.Zero.Web.UI.Metronic");
This code generally stands in Initialize method of the module. Let's explain parameters:
- First parameter defines root folder for files. It matches to root namespace.
- Second parameter defines the Assembly contains files. In this example, I passed the assembly contains this code. But you can pass any assembly contains embedded resources.
- And the last one defines root namespace of files in the assembly. This is the 'default namespace' plus 'folders in the assembly'. Default namespace is generally same as assembly's name but can be changed in properties of the assembly. Here, default namespace is Abp (I changed it), so Metronic folder's namespace is 'Abp.Zero.Web.UI.Metronic'.
Consume embedded files
Consuming embedded files is straightforward:
ASP.NET Boilerplate understands this is an embedded file and gets file from dll exposed before. While it simply works, you can use IncludeScript HtmlHelper extension method of ASP.NET Boilerplate in a razor view:
This will produce the same script tag as shown below:
Only difference is the v=635438748506909100 parameter. This prevents faulty caching of the script by browsers. This value changes only when your dll re-built (actually, it's the last write time of the file) and browser does not cache if it changes. So, using IncludeScript is the suggested way. It also works for non-embedded, physical files. There is also IncludeStyle method for css files.