Question

I have an ASP.NET MVC 4 web app. I am using the RazorGenerator.MsBuild build target to precompile my Razor *.cshtml files. When I build my project locally, everything runs great.

When I deploy the project to Azure Web Sites, I get this error:

"C:\DWASFiles\Sites\my-site-name\VirtualDirectory0\site\repository\MyWebProject\MyWebProject.csproj" (Build;pipelinePreDeployCopyAllFilesToOneFolder target) (1) -> (PrecompileRazorFiles target) ->
C:\DWASFiles\Sites\my-site-name\VirtualDirectory0\site\repository\packages\RazorGenerator.MsBuild.2.0.1\tools\RazorGenerator.targets(21,9): error : An error occurred creating the configuration section handler for system.web.webPages.razor/pages: Could not 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 file specified. (C:\DWASFiles\Sites\my-site-name\VirtualDirectory0\site\repository\MyWebProject\MyWebProject\Views\web.config line 7) [C:\DWASFiles\Sites\my-site-name\VirtualDirectory0\site\repository\server\MyWebProject\MyWebProject\MyWebProject.csproj]

which basically says it can't find version 2.0.0.0 of System.Web.WebPages.Razor

The message is pointing to line 7 of my Views\web.config which is a 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 machine, I can see that it first does a Load Image on

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Razor.dll

and then later does another Load Image on

C:\MyWebProject\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll

and yet another Load Image on

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'm suspecting that it works on my machine and not Azure Web Sites because version 2.0.0.0 of System.Web.WebPages.Razor is not in Azure Web Sites' GAC but version 1.0.0.0 is there.

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>

By looking at Process Monitor, it's looking like MSBuild is reading my web.config file but not any other .config files when building my web assembly (earlier it read ""C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe.config"). Thus, I can't see any other places where I could put these assembly redirects.

What's curious is that the project deploys perfectly on Azure Web Sites if I disable RazorGenerator by setting

<PrecompileRazorFiles>true</PrecompileRazorFiles>

to

<PrecompileRazorFiles>false</PrecompileRazorFiles>

Obviously, the Razor Generator pass doesn't happen with this disabled and thus there are no precompiled views in the result. However, it still runs fine.

Thus, this seems to only be affecting the RazorGenerator "PrecompileRazorFiles" build target and only on Azure Web Sites deploys.

How can I ensure that all build targets, including RazorGenerator's use the right DLLs at all times?

Any other suggestions in how to debug this would be greatly appreciated as well.

Was it helpful?

Solution

This might have been an issue particular to RazorGenerator. One of the authors of the tool looked into it and was able to come up with a workaround that fixed this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top