namespaces not copied into generated file

Sep 27, 2013 at 2:23 PM
hi,

i having a problem where the namespaces from my web.config are no longer being copied into the generated views.

this has worked fine in the past. not sure exactly when it happened.

has there been a change that i'm not aware of??

regards
Coordinator
Sep 27, 2013 at 4:11 PM
I can't repro this with my sample project.

Specifically I tried:
  • Adding <add namespace="Foo.Bar" /> to the namespaces in LibraryViewProject\Views\Web.config
  • Right click on LibraryViewProject\Views\Home\About.cshtml and 'Run custom tool'
After that, the generated file has using Foo.Bar;

Can you check if these exact steps work for you?
Sep 27, 2013 at 6:21 PM
ok, managed to get it to work after I copied and pasted the config from the sample you gave me.
I eye balled it and it seemed the same, but anyways seems to be working now so thanks a lot for you r quick response.
very very much appreciated.

have a nice weekend..
Oct 22, 2013 at 7:11 PM
This problem is back again, but now i've upgraded to MVC 5.
I ran a Redo-RazorGenerator and its not using the namespaces in the Web.config


NOTE: I only add them to the Root web,config file, so that my namespaces are shared by all Areas (we use a lot of them).
NOTE: If I use an @using in the view, that's added as expected.

Should MVC 5 work?
Do i need namespaces in all web.config's?


Example "MyNamespace" below is not added to the generated views.
<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MyNamespace" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>
Example View:
@using Cassette.Views
@using Core.Web.Mvc.Html
@model Web.Areas.SignUp.Models.SignUpModel
@{
    ViewBag.Title = "Sign Up";
    Layout = "../Shared/_Layout.cshtml";
    Bundles.Reference("Client/SignUp");
}

<div class="page-header">
    <h1>Sign up to the Platform</h1>
</div>
Example Generated View:
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18408
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Elevate.Web.Employers.Areas.SignUp.Views.Home
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using System.Web.Mvc.Html;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;
    
    #line 1 "..\..\Areas\SignUp\Views\Home\Index.cshtml"
    using Cassette.Views;
    
    #line default
    #line hidden
    
    #line 2 "..\..\Areas\SignUp\Views\Home\Index.cshtml"
    using Core.Web.Mvc.Html;
    
    #line default
    #line hidden
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
    [System.Web.WebPages.PageVirtualPathAttribute("~/Areas/SignUp/Views/Home/Index.cshtml")]
    public partial class Index : System.Web.Mvc.WebViewPage<Web.Areas.SignUp.Models.SignUpModel>
    {
        public Index()
        {
        }
        public override void Execute()
        {
Oct 22, 2013 at 7:21 PM
Ok it works fine for views in a class library. But the above are in a web project.
is that an issue???
Coordinator
Oct 22, 2013 at 8:23 PM
I haven't gotten around to looking at Mvc 5 as yet. For Mvc 3 and 4, we end up attempting to load the config using the config type system (instead of parsing web.config ourselves) and the new types are probably not recognized which is causing this issue. I can try and have a look at making Mvc 5 work over this week.
Oct 23, 2013 at 8:30 AM
would an assembly redirect not work (on the type system?)
i guess if they've significantly changed then not.
Coordinator
Oct 23, 2013 at 1:56 PM
You'd have to add it to the app.config of the application that runs RazorGenerator - in your case VS. I'm still not sure if that would resolve the issue though
Oct 31, 2013 at 9:16 PM
I'm running into a similar issue. I've upgraded my project that's using the MSBuild RazorGenerator to MVC5. My views that are in top level Views\ControllerName folders (e.g. Views\ControllerName\ActionName.cshtml ) are working but ones that are below that such as "Views\ControllerName\SubFeatureName\ActionName.cshtml" are no longer working. That is, they're no longer using the namespaces that I've specified in Views\web.config. In addition, those subfeature pages are no longer obeying the <pages pageBaseType> whereas the ones in the default locations are working on both points (namespaces + pageBaseType).
Coordinator
Nov 4, 2013 at 1:28 AM
I just uploaded an updated version of RazorGenerator.MsBuild to NuGet. Could you update your package and check if it works for you?
Nov 4, 2013 at 11:58 AM
Hi Pranavkm,

The updated package now lets me compile and run again! Thank you very much for fixing this package for MVC 5 / Razor 3!

(For some odd reason, my startup performance seems quite a bit slower than before I upgraded. After the initial load, things seem fine. I'll be double checking that the PrecompiledMvcEngine is still being used and will try to diagnose it, but wanted to publish this early in case others had run into any startup slowdown when moving to MVC 5.)

Jeff
Coordinator
Nov 4, 2013 at 4:46 PM
Binding redirects in your application should take care of binding it against the latest runtime. Feel free to file a bug if you notice it isn't doing that.
Nov 5, 2013 at 1:11 AM
The binding redirects worked fine once I updated to your latest version. Thanks again!

(The performance issue was caused by me accidentally leaving the CLR's Fusion logging turned on when I left on Friday.. oops)
Nov 30, 2013 at 8:24 PM
Hello,
Hope you had a wonderful Thanksgiving holiday.

I love this tool and use it in all my web projects.

Recently I've created a new MVC 5 Web application and it's ready for deployment. I've installed RazorGenerator for MVC5 package as well as VS extension.

For some reason the generated files do not copy the custom namespaces declared in ..\Views\Web.config file.

Example:
 <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Routing" />
        <add namespace="MyNamespace.Tools"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>
I've tried to install the RazorGenerator.MsBuild package but the result was always the same.

Any help will be greatly appreciated.

Thanks in advance.
Coordinator
Dec 1, 2013 at 5:15 AM
@kobipinhasov: can you please follow the suggestions in this page to try to isolate the behavior? Thanks!
Dec 1, 2013 at 10:08 AM
Thanks David.
Your examples are using MVC 4 and Razor 2.

I took LogOn.cshtml page in Account and changed the first line from:

@model LibraryViewProject.Models.LogOnModel

to

@model LogOnModel

I copied the namespace to the web.config file (inside Views), recompiled the project and Run Custom Tool on LogOn page and it generated the correct file.

However in my MVC 5 it's still not working. Do you have a TestProject with MVC 5 / Razor 3. Pranavkm, mentioned something about config type system.

I also tried declaring the namespaces at the root web.config file but the result was still the same.
Dec 1, 2013 at 6:30 PM
@kobipinhasov: what is the version of your Razor Generator Extension and what is the version of the RazorGenerator.Mvc nuget package? I have a Mvc5 project with RazorGenerator.Mvc 2.2.1 and my Visual Studio has the Razor Generator Extension 1.6.1 and everything works fine.
Dec 1, 2013 at 6:40 PM
I'm also using the latest versions of these files: MVC - 2.2.1 and VS Extension - 1.6.1

One of the differences I see between the TestProject is that my model classes are created by Entity Framework (version 6) and all exist in same namespace - [default project namespace].Models

These classes are visible in Views (because of web.config changes).
Dec 1, 2013 at 7:05 PM
I've created a new MVC 5 project with EF 6 and it works great. I will move files from the old project to the new one. Hope it will work once all is there - unless other factors cause this issue. I will post an update here. Thanks
Coordinator
Dec 1, 2013 at 7:20 PM
Ok, if you ever figure out why it wasn't working for your initial app, please follow up, in case someone else runs into the same thing. Thanks!
Dec 2, 2013 at 11:41 AM
I'm encountering this issue on a large project. the web.config in each area and the root Views folder contains my ViewModel namespace. This isn't getting added to the generated files at all.

Please help!
Coordinator
Dec 2, 2013 at 4:41 PM
@SmogHead: please see this link, per my earlier reply.
Dec 2, 2013 at 9:31 PM
I've created several MVC 5 projects with different packages added and for some reason couldn't get it to work. The namespaces are not being added. Very strange - as if some requirement is missing.
Simple example: an empty mvc 5 project with one controller and one view. Namespace is declared in web,config and recognized by view. The generated file does not contain the namespaces.

I can send you this simple project if you wish.
Coordinator
Dec 2, 2013 at 10:29 PM
Ok, I found the issue. The MVC5 detection logic was not working when the csproj doesn't have a full assembly name. See my change, which I released as 1.6.2.

If you could all verify that it works for you that'd be great, thanks!
Dec 2, 2013 at 11:15 PM
David, no joy with the new version (1.6.2).

Before this version I was able to create new MVC5 projects and RazorGenerator worked without a hitch. It does still work to. However, the project which is encountering the issue is an MVC4 project converted to MVC5 including EF5 -> EF6 upgrade

Everything else is working fine apart from RG.
Coordinator
Dec 2, 2013 at 11:19 PM
Interestingly, when I created a new empty MVC 5 project per @kobipinhasov entry above, it did not work for me. But then after my fix it did. Could you share your csproj file? Also, look at the change I made. Basically there is logic that tries to guess the MVC version by looking for certain patterns in the csproj.
Dec 2, 2013 at 11:40 PM
Ah - Maybe it didn't work before 1.6.1 - Can't be sure.

Ok, the issue was related to the version logic - in the project that was upgraded, the project.csproj file was still referencing System.Web.Mvc version 4. Changed it to 5.0.0.0 and it worked.

Thx David

Steve
Coordinator
Dec 2, 2013 at 11:45 PM
Can you share the relevant snippet from your csproj before you changed it? How can it have been referencing the MVC 4 DLL? It needs to point to the MVC 5 NuGet package to be using MVC 5, no?
Dec 2, 2013 at 11:51 PM
I'll get it on here in a bit/tomorrow - doing a large ReSharper refactor - running like a dog.

As for the version mismatch... I guess the upgrade (uninstall old/install new didn't work very well. The csproj entry looked abnormal.
Dec 3, 2013 at 12:01 AM
Thank you David.

It seems to be working now.
Dec 6, 2013 at 11:00 PM
David,
It works when generated by VS Extension but not with MsBuild package (I'm using version 2.2.2). When will you release the version that supports this fix?
Thanks
Coordinator
Dec 6, 2013 at 11:01 PM
Pranav is the expert of the MsBuild package, so I'll let him reply here!
Coordinator
Dec 6, 2013 at 11:03 PM
I'd assumed David's fix would have accounted for both the vsix and the msbuild task. I can have a look at this over the weekend.
Dec 6, 2013 at 11:48 PM
Thank you pranavkm
Coordinator
Dec 16, 2013 at 4:20 PM
@kobipinhasov Sorry it took me a while to get to this. I tried doing this with a project referencing Mvc 5.0 and it seemed to work fine. Do you think you could share a sample app with me with a repro?
Dec 16, 2013 at 7:47 PM
Edited Dec 16, 2013 at 7:48 PM
@pranavkm Right now I have an MVC 5 project with RazorGenerator.MVC package installed (version 2.2.1). All the views have the custom tool property set to RazorGenerator and when build the project it all gets compiled correctly and works great when deployed. If I go now and uninstall the RazorGenerator.MVC (before that I run the Disable command to clear custom tool property) and install the RazorGenerator.MsBuild package (version 2.2.2) and compile the project - it fails because the namespaces are not copied into the generated files.

Am I doing it correctly? Perhaps I shouldn't uninstall the RazorGenerator.MVC package?
Coordinator
Dec 23, 2013 at 2:30 PM
@kobipinhasov, it should work without the RazorGenerator.Mvc package. Unfortunately I'm still not seeing the issue. This is with a brand new Mvc projects in VS 2012 & 2013. Do you think you could share your project or a repro project?
Dec 25, 2013 at 8:33 AM
Edited Dec 25, 2013 at 8:33 AM
@pranavkm I've created a default MVC 5 project using VS 2013.

First I've installed the RazorGenerator.MVC package and deployed without the Views folder. It worked great.

I've uninstalled the RazorGenerator.MVC package and installed the RazorGenerator.MsBuild package and deployed without the Views folder. The app is not working because it is looking for the Views folder. I've checked the obj folder and it looks like CodeGen is generated with all the files. Perhaps something is missing in configuration.

You can see the example here

Hope this helps

Thanks
Coordinator
Dec 25, 2013 at 1:32 PM
@kobipinhasov The MsBuild package is meant for precompilation while the .Mvc package actually serves the compiled views. So in that sense you do need both packages
Dec 25, 2013 at 1:57 PM
@pranavkm You are right. I've installed the .MVC package, deployed it and it worked as expected. Thanks.
Jan 9, 2014 at 10:31 AM
I really do not know what I'm doing wrong. In my project just does not work.

I created a project from scratch (clean) and it worked, but this project can not implement RazorGenerator [Mvc and MsBuild]

I made a video demonstrating.

Can you help me?
Coordinator
Jan 9, 2014 at 4:31 PM
Edited Jan 9, 2014 at 4:32 PM
@Ridermansb, in your case the problem seems to be mismatched versions of Mvc. You're compiling against Mvc 5.0 but the web.config in your Views directory is referencing Mvc 4.0. Look for the line that says

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version= 4.0.0.0 , Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

The bolded value would need to be changed to 5.0.0.0.
Jan 9, 2014 at 6:26 PM
@pranavkm I tried that but same error http://www.screenr.com/tssN
Mar 20, 2014 at 11:18 PM
I was just having the same issue as others here, with an older project that I had upgraded to MVC 5. In addition to changing the System.Web.Mvc version numbers in web.confg from 4.0.0.0 to 5.0.0.0, I had to change various System.Web.WebPages.Razor from 2.0.0.0 to 3.0.0.0. Now it works.
Mar 21, 2014 at 5:07 AM
I am having the same issue, references are not copied to generated files. I was googling for half day with no success. I added needed namespaces to the view's web.config but they are not in the generated file. I even tried the example web.config from GitHub without any success. This happened when I tried to upgrade MVC from 3 to 4.

I have second project that is working fine and I can not find any significant difference. I tried even diff the project files but they seem "compatible".

Any suggestions what could be wrong? Thanks.
Apr 13, 2014 at 3:42 AM
I have upgraded my MVC project from 5.1.1 to 5.1.2 and the issue is happening again. I have RazorGenerator.Mvc 2.2.2 (nuget package), Razor Generator 1.6.3 (VS extension) and VS 2013 Update 2 RC. I have two different projects: one with Mvc 5.1.1 that RG works, and another with 5.1.2 that RG does not work.
May 25, 2014 at 4:24 AM
Anyone having the same issue? I have disableb RG for that project since then.
May 27, 2014 at 5:30 AM
I solved a similar issue by creating a file razorgenerator.directives in the same folder as my web csproj file with the following:
RazorVersion: 3
You may also need to delete any generated *.cs files as well, to force their re-generation.

My symptoms were very similar to the above. Namespaces from my Web.config file were not being applied to files generated using RazorGenerator.MsBuild. Although, if I updated any cshtml file (just the date stamp was enough; no change in the file itself) the cs file would regenerate correctly (with all namespaces included), which I find totally inexplicable!

After poking through the current source code, I was wondering if the generator was using the incorrect version of Razor (I recently upgraded to MVC 5.1). Seems RazorGenerator guessed my version incorrectly. Adding the directives file above overrides the guessing process and tells RazorGenerator to use version 3 of Razor (which goes with MVC5). I never actually confirmed this was what was actually happening (even after getting ProcMon and WPR traces). But the directives file did fix my build server and local dev machine.

I think the problem is in Core.HostManager.IsMvcProject(). When you have MVC 5.1 installed, the version check in your csproj file for version 5.0.0.0 of System.Web.MVC fails because its version is 5.1.0.0 (and, I assume will be changing more regularly with the way they are releasing these days).

I'd prefer the whole build to blow up if it can't guess which Razor version to use. Or perhaps just use the version of System.Web.Razor as it seems more stable. But I'll leave the developers to make a call on that one.

Also, I'm not using the vsix, just the MsBuild and MVC nugets.
Coordinator
May 27, 2014 at 5:11 PM
@ligos, we do use System.Web.Razor as part of the version detection bit:
else if ((content.IndexOf("System.Web.Mvc, Version=5.0.0.0", StringComparison.OrdinalIgnoreCase) != -1) ||
    (content.IndexOf("System.Web.Razor, Version=3.0.0.0", StringComparison.OrdinalIgnoreCase) != -1) ||
    (content.IndexOf("Microsoft.AspNet.Mvc.5.0.0", StringComparison.OrdinalIgnoreCase) != -1))
{
    // The project references Razor v3
    razorRuntime = RazorRuntime.Version3;
}
Do you think you could share a snippet of your csproj file? It would help us make the detection piece a bit more sturdy.
May 27, 2014 at 10:24 PM
Certainly! The relevant references (somehow, I've managed to omit Microsoft.AspNet.Mvc, though my project still works):
    <Reference Include="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\packages\Microsoft.AspNet.Mvc.5.1.2\lib\net45\System.Web.Mvc.dll</HintPath>
    </Reference>
...
    <Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\packages\Microsoft.AspNet.Razor.3.1.2\lib\net45\System.Web.Razor.dll</HintPath>
    </Reference>
So, without Microsoft.AspNet.Mvc and with System.Web.Mvc, Version=5.1.0.0, that will cause the check to fail.

You could get away with reducing your string comparisons to keep looking for version 5, but any minor revisions of it:
else if ((content.IndexOf("System.Web.Mvc, Version=5.", StringComparison.OrdinalIgnoreCase) != -1) ||
    (content.IndexOf("System.Web.Razor, Version=3.", StringComparison.OrdinalIgnoreCase) != -1) ||
    (content.IndexOf("Microsoft.AspNet.Mvc.5.", StringComparison.OrdinalIgnoreCase) != -1))
{
    // The project references Razor v3
    razorRuntime = RazorRuntime.Version3;
}
I'll see if I can put together a pull request for a fail fast scenario where the process throws if it can't determine the correct Razor version to use, rather than silently falling back to v1.
Sep 1, 2014 at 7:49 AM
@ligos thanks for that, I think you're spot on. When I upgraded to mvc 5.2.2.0 I ran into this issue. I can see the sturdy check has been committed to source on July 31st but that the nuget package has not been updated since. It looks like it will be a proper fix and would second a release of this sooner rather than later.
Sep 1, 2014 at 2:13 PM
In our solution after installing VS 2013 Update 3 and latest NuGet package for Microsoft.AspNet.Mvc we actually have references in *.csproj without version information at all. Like this:
<Reference Include="System.Web.Razor">
  <HintPath>..\..\..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll</HintPath>
  <Private>True</Private>
</Reference>
and that's causing the bug.

Isn't there some better method of determining razor version? Like looking for
<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
</appSettings>
in the configuration file, for example?
Sep 2, 2014 at 9:48 AM
Any idea when this is going to be resolved - It's causing me serious pain
Sep 2, 2014 at 4:03 PM
@SmogHead: I solved this problem using Ligos solution on this thread:

""I solved a similar issue by creating a file razorgenerator.directives in the same folder as my web csproj file with the following:""

RazorVersion: 3
Coordinator
Sep 2, 2014 at 4:36 PM
but that the nuget package has not been updated since
I updated the RazorGenerator.MsBuild NuGet package to include this change - the VSIX hasn't been fixed. I'll work with @davidebbo to get a release of that today. Hopefully that should sort this out without having to use a directive.
Sep 2, 2014 at 4:38 PM
Great if you can - I have compiled the project and update the binaries manual replacing the ones from the VSIX to get it working
Coordinator
Sep 2, 2014 at 7:38 PM
The fix is now in the gallery. Can you try updating the VSIX?
Sep 2, 2014 at 7:43 PM
That would have seemed to have resolved the issue - Thank you very much
Sep 25, 2014 at 3:05 PM
I am having the exact same issue on my build server. When i compile on my machine it works fine but as soons as i run a build on my build server or through azure deployment the namespace for the viewmodels, etc aren't added.

packages version:
Microsoft.AspNet.Mvc.5.2.2
RazorGenerator.MsBuild.2.2.6
RazorGenerator.Mvc.2.2.3


Locally generated code
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.34014
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace THENAMESPACE.Web.MVC.Views.Account
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using System.Web.Mvc.Html;
    using System.Web.Optimization;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;
    using THENAMESPACE.Contracts.UI.ViewModel;
    using THENAMESPACE.Web.Extension;
    using THENAMESPACE.Web.Extension.Bootstrap;
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
    [System.Web.WebPages.PageVirtualPathAttribute("~/Views/Account/Index.cshtml")]
    public partial class Index : System.Web.Mvc.WebViewPage<AccountViewModel>
Build Server
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.33440
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace THENAMESPACE.Web.MVC.Views.Account
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using System.Web.Mvc.Html;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
    [System.Web.WebPages.PageVirtualPathAttribute("~/Views/Account/Index.cshtml")]
    public partial class Index : System.Web.Mvc.WebViewPage<AccountViewModel>
    {
Any ideas / help is much appreciated!
Coordinator
Sep 25, 2014 at 7:34 PM
When using the VSIX, all the generation happens at development, so the build server would not be affected. But when using RazorGenerator.MsBuild, the generation does happen on the build server.

Not sure why it wouldn't work if you have the latest package, unless somehow it's still using the old one.
Sep 29, 2014 at 8:21 AM
Edited Sep 29, 2014 at 8:29 AM
davidebbo wrote:
When using the VSIX, all the generation happens at development, so the build server would not be affected. But when using RazorGenerator.MsBuild, the generation does happen on the build server.

Not sure why it wouldn't work if you have the latest package, unless somehow it's still using the old one.
I dont use the VSIX. I let the MSBuild task do all the work so that the steps performed to create a build of the site are the same on the development machines and build server.

But i got it working again:
  • Cleaned working dir on build server
  • Uninstall-Package for both MsBuild & MVC packages.
  • Verified the build on the build server was working without RazorGenerator
  • Reinstalled packages
  • Works!
Thanks for your help david!
Coordinator
Sep 29, 2014 at 2:23 PM
Thanks for following up. There must be some bug in the detection logic that causes it to get confused when things aren't quite right.
Dec 23, 2014 at 10:51 PM
I'm facing the same bug. View generation works fine on my machine, but it fails to pick up namespaces from a web.config on other developer's machine. We work on the same solution with the same latest RazorGenerator extension installed.
Jan 9, 2015 at 12:42 AM
Following a recent upgrade to MVC 5.2, we had an issue where builds started failing on our build server with the latest RazorGenerator packages.

Ultimately, the problem for us ended up being that RazorGenerator was referencing System.Web.Mvc 5.0.0, rather than 5.2.2. We manually installed System.Web.Mvc 5.0.0 in the GAC and everything started working again.

Are there any plans for a new RazorGenerator package that targets MVC 5.2?
Coordinator
Jan 9, 2015 at 3:26 AM
Edited Jan 9, 2015 at 3:29 AM
@jsholzer: is that when using the RazorGenerator.MsBuild package?

I saw you opened this issue, so let's discuss there. This sounds unrelated to the issue in this thread, which is about namespace imports.
Apr 2, 2015 at 1:37 AM
How I fixed mine!

TLDR - deleted the output directory set in MSbuild as it contained old files.

Longer Story
I had a PagingModel. I moved it from the consumer project to be reused in my base project (RazorGenerator).

So with MsBuild (not the RazorGenerator.MsBuild) i was getting errors like
The type or namespace name PagingModel does not exist in the namespace.
Ok, it was complaining that it could not find Consumer.PagingModel when it should be BaseProject.PagingModel. It used to be Consumer.PagingModel!
After trying many crazy, time consuming and headache causing things; only after deleting the OutDir location, my Msbuild finally succeeded. So now, deleting the OutDir is part of my build script.

P.S. +1 RazorGenerator!
Jul 31, 2015 at 12:10 PM
Edited Aug 3, 2015 at 9:01 AM
The only thing that helped me was adding razorgenerator.directives files with RazorVersion: 3.