4

I am currently working on a project which features a plugin-like system. Once the web project starts up it looks for plugin dlls and build up the GUI. The dlls contain embedded views, and embedded resources like pictures or javascripts.

  • I use RazorGenerator(VS Plugin) to generate the cs files from the views, The build action of the views is set to 'embedded resource' and the custom tool is set to 'RazorGenerator'

  • I use a custom Virtual Path Provider (a very similar to this one)

  • I register my virtual path provider with this workaround i found on the net (it is a must since it is not working as intented if i dont use this):

        var assemblyResourceProvider = new AssemblyResourceProvider();
        var hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
        if (hostingEnvironmentInstance == null)
            return;
    
        var mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
        if (mi == null)
            return;
    
        mi.Invoke(hostingEnvironmentInstance, new object[] { assemblyResourceProvider });
    
  • I use this at my RouteConfig.cs to make the embedded script and picture files work:

       routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|png|jpg|exe)(/.*)?" });
    
  • I add these lines (there are more) to my web.config to tell asp to use my path provider for my embedded sources:

      <add name="AspNetStaticFileHandler-PNG" path="*.png" verb="GET,HEAD" type="System.Web.StaticFileHandler"/>
    
  • I use the Boc.Web.PrecompiledViews dll to register the path attributes generated by RazorGenerator

    BoC.Web.Mvc.PrecompiledViews.ApplicationPartRegistry.Register(assembly);
    

Everything is working as intended in Visual Studio. The views and resources embedded in a dll are showing and working flawlessly. I also use IIS 7.5 to run my web app from Visual Studio. All of the possibilities work:

  • it works if i give the virtual path generated by Razor Generator (ex: "~/Views/ViewTest/Test)
  • it works if i give the Dll resources path which uses my resourceprovider (ex: "DllResources/ViewTest.dll/Views/ViewTest/Test.cshtml)

However, after i deploy my web app and run it using IIS 7.5, the Views(only the views!) are not showing! If i address the views with the virtual path (option 1), IIS gives this error message:

    The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

if i address the views with the DllResources path (option 2), IIS gives this error message:

    The file '/Views/ViewTest/DllResources/EmbeddedResourceTest/Views/ViewTest/Test.cshtml' has not been pre-compiled, and cannot be requested.

I dont know what to do now to make it work. I have tried to replace every single step with other solutions. The result is still the same. Flawlessly working in VS, but the views are not showing after deployment.

Is it some config for the IIS what is missing? am i missing something from the web.config? Please help me with this issue.

Thanks, Norbert

4

1 回答 1

0

好的,经过 1 周的痛苦,我终于想出了解决方案。问题在于 Web 项目的发布。这是我所做的:

我一直在 Microsoft.Net 文件夹中使用 aspnet_compiler 发布我的 Web 应用程序。这是由成功的 Web 项目构建触发的构建后事件。我删除了这个事件,并将其替换为 Web 项目的 .csproj 文件中的“AfterBuild”脚本。我在这个问题上找到了脚本。使用这种新的发布方法,嵌入式视图最终会显示出来。

希望这对将来的某人有所帮助。

问候,

于 2012-10-26T06:50:34.500 回答