Views do not recompile if namespaces section was changed in web.config from views forlder.
So as the exmaple of an issue I created new project and replaced some extensions and objects from web project to new one. Then I've added new namespace to system.web.webPages.razor -> pages -> namespaces section of web.config located in 'Views' folder and got the errors while building project. The reason is missing namespace in views.
On developer machine I can just clear folder with compiled views but what I need to do on production server to force views recompilation, I have no access to production server.
I really like RazorGenerator, it's pretty cool feature!!! Thanks for attention.
Views do not recompile if namespaces section was changed in web.config from views forlder
RazorGenerator currently does not check the web.config last-modified-times or compare file hashes to trigger recompilation - because the main use-case of RazorGenerator is when you don't want to publish the cshtml files.
On developer machine I can just clear folder with compiled views but what I need to do on production server to force views recompilation, I have no access to production server.
When you're developing, ASP.NET will use its own BuildManager with its own Razor view-engine which does check web.config files, and won't invoke RazorGenerator - when you publish the project will defer to RazorGenerator always.
It sounds like you're asking how precompile your views while also allowing them to be updatable on the server?
Hi Jehoel! Thanks for your reply.
It sounds like you're asking how precompile your views while also allowing them to be updatable on the server?
I need a way to force rebuild views by RazorGenerator for Release configuration. If there is no such setting, I think I need to update deployment script to delete CodGen folder before building a web project.
I need a way to force rebuild views by RazorGenerator for Release configuration.
They should rebuild any time you do a project Rebuild - there's nothing special in the RazorGenerator MSBuild targets.
What does your build process look like?
Hello there! May be a test case will be helpful to understand an issue...
- Visual Studio 2017
- .NET Framework 4.6.1
- C#
- Create ASP.NET MVC 5 project (namespace
Web) with RazorGenerator.Mvc and RazorGenerator.MsBuild dependencies. By default namespaceWebwill be added to ~/Views/Web.config filesystem.web.webPages.razor -> pages -> namespacessection as<add namespace="Web" />child. - Create a class
NumberExt(namespaceWeb) in the root of web app project. Add there some const or static fieldint PercentPrecision. - Use
NumberExt.PercentPrecisionsomewhere in_Layout.cshtmland run the application. - Change
NumberExtnamespace fromWebtoWeb.Common. - Append
Web.Commonnamespace to ~/Views/Web.config filesystem.web.webPages.razor -> pages -> namespacessection as<add namespace="Web.Common" />child. - Restart solution to allow Visual Studio update shared namespaces in views syntax, otherwise it will cause an error 'Missing Reference'.
- Try to build the project.
Result: You will have an error "The name 'NumberExt' does not exist in the current context" for compiled _Layout.cshtml.cs because using namespaces were not updated inside the compiled file.
Expected Result: Updated using namespaces in compiled views.
Thanks for attention and have a good day!
Ok,
I've fixed it by declearing RazorViewsCodeGenDirectory in web app .csproj file before importing RazorGenerator.MsBuild.targets:
<PropertyGroup Label="RazorGenerator">
<RazorViewsCodeGenDirectory Condition=" '$(RazorViewsCodeGenDirectory)' == '' ">$(MsBuildProjectDirectory)\obj\CodeGen\</RazorViewsCodeGenDirectory>
</PropertyGroup>
Appended task RemoveDir to target BeforeBuild like these:
<Target Name="BeforeBuild">
_YourBeforeBuildActionIfAny_
<RemoveDir Directories="$(RazorViewsCodeGenDirectory)" Condition="Exists('$(RazorViewsCodeGenDirectory)')" ContinueOnError="true" />
</Target>