This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
Asp.net core 2.1.0 RazorTemplateEngine not working #2422
Labels
Comments
Thanks for contacting us, @eguzelkucuk. |
@ajaybhargavb, can you please look into this? The referenced thread has some info too |
@eguzelkucuk, we changed the way we initialize Razor and it's extensions recently. To achieve what you are trying to do you now need to implement a custom public class MyRazorProjectFileSystem : RazorProjectFileSystem
{
private readonly RazorProjectFileSystem _inner;
public MyRazorProjectFileSystem(RazorProjectFileSystem inner)
{
_inner = inner;
}
public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
{
var items = _inner.EnumerateItems(basePath);
return items.Select(i => new MinifiedRazorProjectItem(i));
}
public override RazorProjectItem GetItem(string path)
{
var item = _inner.GetItem(path);
return new MinifiedRazorProjectItem(item);
}
private class MinifiedRazorProjectItem : RazorProjectItem
{
private readonly RazorProjectItem _inner;
public MinifiedRazorProjectItem(RazorProjectItem inner)
{
_inner = inner;
}
public override string BasePath => _inner.BasePath;
public override string FilePath => _inner.FilePath;
public override string PhysicalPath => _inner.PhysicalPath;
public override bool Exists => _inner.Exists;
public override Stream Read()
{
return Minify(_inner.Read());
}
private Stream Minify(Stream markup)
{
// Your minification logic
return markup;
}
}
} And then you register it in // After the call to services.AddMvc()
var descriptor = services.Single(s => s.ServiceType == typeof(RazorProjectFileSystem));
services.AddSingleton<RazorProjectFileSystem>(s =>
{
var existingFileSystem = (RazorProjectFileSystem)ActivatorUtilities.GetServiceOrCreateInstance(s, descriptor.ImplementationType);
return new MyRazorProjectFileSystem(existingFileSystem);
}); |
Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments. |
The RazorTemplateEngine should be removed? |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am doing html minify on razortemplate engine on compiletime on asp.net core, but razortemplate engine does not work after updating project asp.net core 2.1.0.
It does not call CreateCodeDocument method. sample code below.
startup.cs
services.AddSingleton<RazorTemplateEngine, CustomRazorTemplateEngine>();
The text was updated successfully, but these errors were encountered: