payload: {"action":"created","issue":{"url":"https://api.github.com/repos/Antaris/RazorEngine/issues/476","repository_url":"https://api.github.com/repos/Antaris/RazorEngine","labels_url":"https://api.github.com/repos/Antaris/RazorEngine/issues/476/labels{/name}","comments_url":"https://api.github.com/repos/Antaris/RazorEngine/issues/476/comments","events_url":"https://api.github.com/repos/Antaris/RazorEngine/issues/476/events","html_url":"https://github.com/Antaris/RazorEngine/issues/476","id":236630461,"node_id":"MDU6SXNzdWUyMzY2MzA0NjE=","number":476,"title":"TemplateBase missing Context fields","user":{"login":"adriangodong","id":1140137,"node_id":"MDQ6VXNlcjExNDAxMzc=","avatar_url":"https://avatars3.githubusercontent.com/u/1140137?v=4","gravatar_id":"","url":"https://api.github.com/users/adriangodong","html_url":"https://github.com/adriangodong","followers_url":"https://api.github.com/users/adriangodong/followers","following_url":"https://api.github.com/users/adriangodong/following{/other_user}","gists_url":"https://api.github.com/users/adriangodong/gists{/gist_id}","starred_url":"https://api.github.com/users/adriangodong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriangodong/subscriptions","organizations_url":"https://api.github.com/users/adriangodong/orgs","repos_url":"https://api.github.com/users/adriangodong/repos","events_url":"https://api.github.com/users/adriangodong/events{/privacy}","received_events_url":"https://api.github.com/users/adriangodong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-06-17T01:30:40Z","updated_at":"2019-08-09T12:44:23Z","closed_at":null,"author_association":"NONE","body":"`RazorEngine.Templating.TemplateBase` and `RazorEngine.Templating.TemplateBase<T>` are missing `BeginContext`, `EndContext`, and `Context` members. These members are called from `aspnet_compiler` generated view classes.\r\n\r\nI propose we add empty/fake members that will resolve the compiler errors and make working with RazorEngine more seamless. I'm not sure how widespread or common this issue is, I welcome any feedback if there's a simpler workaround. I'm willing to work on a PR to resolve this if there's a consensus.\r\n\r\n## Rationale and Usage\r\n\r\nCompiling views using `MvcBuildViews` msbuild task is a crucial step to avoid JIT view compilation errors. The task will run `aspnet_compiler` on every build. The compiler does not have a way to whitelist / blacklist folders. This means `aspnet_compiler` will transform Razor templates into C# classes for all `.cshtml` files in the project, including those inherited from `RazorEngine.Templating.TemplateBase`.\r\n\r\nHere's a sample of `aspnet_compiler`-generated C# class that fails build:\r\n\r\n```\r\nnamespace ASP {\r\n\r\n    public class _Page_EmailTemplates_Templates__EmailLayout_cshtml : RazorEngine.Templating.TemplateBase {\r\n\r\n        public _Page_EmailTemplates_Templates__EmailLayout_cshtml() {\r\n        }\r\n        \r\n        protected ASP.global_asax ApplicationInstance {\r\n            get {\r\n                return ((ASP.global_asax)(Context.ApplicationInstance)); // <-- compile error\r\n            }\r\n        }\r\n\r\n        public override void Execute() {\r\n            BeginContext(\"~/EmailTemplates/Templates/_EmailLayout.cshtml\", 144, 15, false); // <-- compile error\r\n            ...\r\n            EndContext(\"~/EmailTemplates/Templates/_EmailLayout.cshtml\", 144, 15, false); // <-- compile error\r\n        }\r\n\r\n        ...\r\n    }\r\n}\r\n```\r\n\r\nAdding the members used by the generated class will allow RazorEngine-consumed Razor templates to sit side-by-side with ASP.NET MVC Razor templates and allow `MvcBuildViews` task to run without any issue.\r\n\r\n## Proposed API\r\n\r\nAdd the following members to `TemplateBase` and `TemplateBase<T>`:\r\n\r\n```\r\nprotected void BeginContext(\r\n    string virtualPath,\r\n    int startPosition,\r\n    int length,\r\n    bool isLiteral)\r\n{\r\n}\r\n\r\nprotected void EndContext(\r\n    string virtualPath,\r\n    int startPosition,\r\n    int length,\r\n    bool isLiteral\r\n)\r\n{\r\n}\r\n\r\nprotected Fake Context { get; set; }\r\n\r\npublic class Fake\r\n{\r\n    public object ApplicationInstance { get; set; }\r\n}\r\n```\r\n\r\n## Workarounds\r\n\r\nTo avoid this issue without changing RazorEngine code, there are several workarounds:\r\n\r\n* Don't run `MvcBuildViews` / `aspnet_compiler`. Not really an option unless you have a separate Razor templates validation tool.\r\n\r\n* Create a build task that renames affected Razor templates so that `aspnet_compiler` don't include those files. There should be another build task that runs after `MvcBuildViews` that reverts the changes. (untested)\r\n\r\n* Move Razor templates consumed by RazorEngine out of the ASP.NET MVC project so that `aspnet_compiler` does not generate C# classes for templates inheriting `RazorEngine.Templating.TemplateBase`. Difficulty of moving will be affected by dependencies/complexity of the model classes used in the templates."},"comment":{"url":"https://api.github.com/repos/Antaris/RazorEngine/issues/comments/519904687","html_url":"https://github.com/Antaris/RazorEngine/issues/476#issuecomment-519904687","issue_url":"https://api.github.com/repos/Antaris/RazorEngine/issues/476","id":519904687,"node_id":"MDEyOklzc3VlQ29tbWVudDUxOTkwNDY4Nw==","user":{"login":"BeniGemperle","id":6669093,"node_id":"MDQ6VXNlcjY2NjkwOTM=","avatar_url":"https://avatars2.githubusercontent.com/u/6669093?v=4","gravatar_id":"","url":"https://api.github.com/users/BeniGemperle","html_url":"https://github.com/BeniGemperle","followers_url":"https://api.github.com/users/BeniGemperle/followers","following_url":"https://api.github.com/users/BeniGemperle/following{/other_user}","gists_url":"https://api.github.com/users/BeniGemperle/gists{/gist_id}","starred_url":"https://api.github.com/users/BeniGemperle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeniGemperle/subscriptions","organizations_url":"https://api.github.com/users/BeniGemperle/orgs","repos_url":"https://api.github.com/users/BeniGemperle/repos","events_url":"https://api.github.com/users/BeniGemperle/events{/privacy}","received_events_url":"https://api.github.com/users/BeniGemperle/received_events","type":"User","site_admin":false},"created_at":"2019-08-09T12:44:23Z","updated_at":"2019-08-09T12:44:23Z","author_association":"NONE","body":"Thanks @adriangodong. My Workaround was to create another class extending TemplateBase<T> and inherit from that in all affected cshtml-files:\r\n```c#\r\npublic class MyRazorTemplate<T> : RazorEngine.Templating.TemplateBase<T>\r\n{\r\n    protected void BeginContext(string virtualPath, int startPosition, int length, bool isLiteral) { }\r\n\r\n    protected void EndContext(string virtualPath, int startPosition, int length, bool isLiteral) { }\r\n\r\n    protected Fake Context { get; set; }\r\n\r\n    public class Fake\r\n    {\r\n        public object ApplicationInstance { get; set; }\r\n    }\r\n}\r\n```"}}
other: {"actor":{"display_login":"BeniGemperle"}}