Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading RazorGenerator.MSBuild from 2.2.6 to 2.3.4 breaks rendering #29

Closed
asbjornu opened this issue Jul 17, 2015 · 11 comments
Closed

Comments

@asbjornu
Copy link

I just tried to upgrade RazorGenerator.MsBuild from version 2.2.6 to 2.3.4 and RazorGenerator.Mvc from version 2.2.3 to version 2.3.5. For reasons unbeknownst to me, that broke rendering of all views. In some circumstances, I get this exception:

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Areas/Redacted/Views/Projects/Index.cshtml ~/Areas/Redacted/Views/Shared/Index.cshtml ~/Views/Projects/Index.cshtml ~/Views/Shared/Index.cshtml

With the following stack trace:

at System.Web.Mvc.ViewResult.FindView(ControllerContext context) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult)

In other circumstances, I get no exception, but a view rendered without a layout. This brings up a lot of questions I would love to have answered:

  1. Has there been any breaking changes between the mentioned versions of these two packages?
  2. How does the two packages relate to each other?
  3. How do the two packages maintain backward compatibility?
  4. How is the backward compatibility between the two packages expressed in terms of the version number? Can we expect every minor version of 2 to be compatible both ways?
  5. Why is the last version of RazorGenerator.MsBuild 2.3.4 while it's 2.3.5 for RazorGenerator.Mvc?

Thanks!

@davidebbo
Copy link
Contributor

Note sure if 2.3.4 vs 2.3.5 is the issue, but just in case I pushed RazorGenerator.MsBuild 2.3.5. Can you see if that makes a difference?

If it's still broken, I'll let @pranavkm comment as he's the RazorGenerator.MsBuild expert.

@pranavkm
Copy link
Member

We typically don't make breaking changes between point releases, but there were a few changes to how the msbuild target locates the cshtml files from your project. We could start by verifying the views are actually being compiled in to your assembly.

Could you check if the generated files appear in the obj directory of your project and that the views get compiled in to your project assembly?

@asbjornu
Copy link
Author

@davidebbo Upgrading to 2.3.5 had no effect, sadly. @pranavkm Yes, the folder obj/CodeGen/Views contain all of the views. In dotPeek I can see that the compiled assembly contains an ASP namespace in which classes like _Views_Compare_Index_cshtml reside. Does this sound correct? What else might cause the views from being loaded correctly?

I'm using the CompositePrecompiledMvcEngine, if that makes any difference.

@pranavkm
Copy link
Member

@asbjornu that looks right so far. Can you check if the VirtualPathAttribute for the precompiled file in obj/CodeGen/Areas/Redacted/Views/Index.cs looks correct (i.e. it maps to ~/Areas/Redacted/Views/Shared/Index.cshtml)? You could also try debugging CompositePrecompiledMvcEngine - dropping the cs file from https://github.com/RazorGenerator/RazorGenerator/blob/master/RazorGenerator.Mvc/CompositePrecompiledMvcEngine.cs into your application should suffice.

@asbjornu
Copy link
Author

asbjornu commented Aug 4, 2015

@pranavkm Thanks for pushing me in the right direction! After comparing the contents of the CodeGen folder of the branch where RazorGenerator is upgraded and where it's still at version 2.2.6 (master), I discovered that the upgraded branch was missing a lot of .cshtml.cs files. For some reason, the missing views were included in the .csproj file with <None>. Changing them to <Content> fixed the problem.

Investigating this further, there's actually three views that have a None build action in master:

  • ~/Views/Projects/Index.cshtml
  • ~/Views/Shared/_Layout.cshtml
  • ~/Views/Shared/_Edit.cshtml

On the master branch, running on RazorGenerator.MsBuild version 2.2.6 and RazorGenerator.Mvc version 2.2.3, this works just fine. After upgrading to version 2.3.5, having Index.cshtml as None breaks. I assume shared views don't need to be Content as they are implicitly compiled as part of all other views?

@pranavkm
Copy link
Member

pranavkm commented Aug 4, 2015

@asbjornu seems like it's a behavioral change introduced as part of #8 (#8. We're only pulling Content files from Views:

https://github.com/RazorGenerator/RazorGenerator/blob/master/RazorGenerator.MsBuild/RazorGenerator.MsBuild.targets#L14-L15

My guess is we could additionally include all files marked with None in addition to the ones with Content by default. @cjberg, thoughts?

@asbjornu
Copy link
Author

asbjornu commented Aug 6, 2015

@pranavkm I see. If you don't include None files, perhaps you could issue a warning if a .cshtml file is included with None?

@cjberg
Copy link
Contributor

cjberg commented Aug 6, 2015

@pranavkm You're correct, None should be included as it can be used when one e.g. don't want to include the cshtml file for deployment. (I didn't have a single view file in that item group when I ran tests, because my main project needs to deploy the cshtml files and fails the build if one isn't in the Content group. That's so typical!)

I think we only need to add ;@(None) in the targets file, like this:

<RazorSrcFiles Condition=" '@(RazorSrcFiles)' == '' and '%(Extension)' == '.cshtml' "
    Include="@(Content);@(None)" />

I'm on vacation at the moment, so I can't test it or create a pull request, but I see no reason why it wouldn't work.

@asbjornu
Copy link
Author

asbjornu commented Aug 6, 2015

@cjberg Good point. Skip the warning. :)

@pranavkm
Copy link
Member

Fixed in 2011802. Package uploaded to NuGet - https://www.nuget.org/packages/RazorGenerator.MsBuild

@asbjornu
Copy link
Author

Brilliant! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants