I have an ASP.NET MVC 4 web application. I use RazorGenerator.MsBuild to precompile Razor * .cshtml files. When I create my project locally, everything works fine.
When I deploy the project to Azure Web Sites, I get this error:
"C: \ DWASFiles \ Sites \ myName \ VirtualDirectory0 \ site \ repository \ MyWebProject \ MyWebProject.csproj" (Build; pipePreDeployCopyAllFilesToOneFolder target) (1) β (PrecompileRazorFiles target) β
C: \ DWASFiles \ Sites \ my site name \ VirtualDirectory0 \ site \ repositories \ packages \ RazorGenerator.MsBuild.2.0.1 \ Tools \ RazorGenerator.targets (21,9): Error: An error occurred while creating the configuration section handler for system.web.webPages.razor / pages: Failed to load file or assembly 'System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. The system cannot find the specified file. (C: \ DWASFiles \ Sites \ MyName \ VirtualDirectory0 \ site \ repository \ MyWebProject \ MyWebProject \ Views \ web.config line 7) [C: \ DWASFiles \ Sites \ My-Site-Name \ VirtualDirectory0 \ site \ repositories \ server \ MyWebProject \ MyWebProject \ MyWebProject.csproj]
which basically says it cannot find version 2.0.0.0 for System.Web.WebPages.Razor
The message points to line 7 of my Views \ web.config, which is the standard MVC 4 line in the configSection.sectionGroup section:
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
By running Process Monitor on my local computer, I see that it first downloads the image to
C: \ Program Files (x86) \ Microsoft ASP.NET \ ASP.NET Web Pages \ v1.0 \ Assemblies \ System.Web.WebPages.Razor.dll
and then performs another load image on
C: \ MyWebProject \ packages \ Microsoft.AspNet.WebPages.2.0.30506.0 \ Lib \ net40 \ System.Web.WebPages.Razor.dll
and another image upload to
C: \ MyWebProject \ packages \ RazorGenerator.MsBuild.2.0.1 \ tools \ v2 \ System.Web.WebPages.Razor.dll
and then finally another load image on
C: \ Windows \ Microsoft.NET \ assembly \ GAC_MSIL \ System.Web.WebPages.Razor \ v4.0_2.0.0.0__31bf3856ad364e35 \ System.Web.WebPages.Razor.dll
from the GAC.
I suspect that it works on my machine, not on Azure Web Sites, because version 2.0.0.0 of System.Web.WebPages.Razor is not in the GAC Azure Web Sites, but there is version 1.0.0.0.
In my main web.config file, I have these lines in my runtime.assemblyBinding section:
<dependentAssembly> <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly>
Looking at Process Monitor, it looks like MSBuild reads my web.config file, but not any other .config files when creating my web assembly (he previously read "C: \ Windows \ Microsoft.NET \ Framework \ v4 .0.30319 \ msbuild.exe.config "). Thus, I do not see other places where I could redirect these assemblies.
Curiously, the project deploys well on Azure Web Sites if I turn off RazorGenerator by installing
<PrecompileRazorFiles>true</PrecompileRazorFiles>
to
<PrecompileRazorFiles>false</PrecompileRazorFiles>
Obviously, the Razor Generator run does not happen with it disabled and, therefore, there are no precompiled views as a result. However, it still works fine.
Thus, this, apparently, only affects the purpose of the RazorGenerator assembly "PrecompileRazorFiles", and only for the deployment of Azure websites.
How can I guarantee that all build targets, including RazorGenerator, always use the correct DLLs?
Any other suggestions on how to debug this would also be greatly appreciated.