RazorGenerator - View already defines a member error

Jul 3, 2014 at 3:38 PM
I'm using the RazorGenerator extension along with RazorGenerator.Mvc, RazorGenerator.MsBuild, and RazorGenerator.Templating.

I have a simple view like this:
    @* Generator : Template *@

    @functions {
        public string Model { get; set; }
    }

    Hello, @Model
I get the following errors:
    The type 'SampleProject.Views.Account.EmailTemplate' already contains a definition for 'Model'
    Type 'SampleProject.Views.Account.EmailTemplate' already defines a member called 'Execute' with the same parameter types
I've verified that the file's build action is set to None and custom tool is set to RazorGenerator. Getting rid of the @functions area gets rid of the Model already defined errors, but the "Already defines a member called 'Execute'" remains.
Coordinator
Jul 3, 2014 at 4:40 PM
If I add a Model prop like this to my sample, I don't get this error. Maybe try looking for what might be different in yours?

Note that if you are using a plain template, MVC should be irrelevant, so I suggest trying to isolate to a non MVC repro like my test repo.
Jul 3, 2014 at 6:44 PM
Edited Jul 3, 2014 at 6:51 PM
The error occurs when I include RazorGenerator.MsBuild in my project. Does this mean that I cannot use both the VS RazorGenerator extension and RazorGenerator.MsBuild in my project? I'm using the VS extension to generate the classes for use with RazorGenerator.Templating.
Coordinator
Jul 3, 2014 at 8:46 PM
Yes, that might be the problem. @pranavkm is the expert on RazorGenerator.MsBuild, but I think it generates code at build time for all the razor templates. So if in addition to that, a template has pre-generated code using the extension, I can see how it would conflict.

Pranav might have more to say about that.
Coordinator
Jul 3, 2014 at 8:48 PM
You shouldn't need both the extension and RazorGenerator.MsBuild. They do the same thing in different ways - which is precompiling view files. In this case the same type is generated twice which is what's likely causing the issue.
Jul 3, 2014 at 8:53 PM
Without the extension, compilation fails stating that the view is not found, e.g.
string viewHtml = new MyViewTemplate { someVar = someOtherVar }.TransformText();
// "MyViewTemplate" only exists when generated with Razor extension
Coordinator
Jul 3, 2014 at 8:55 PM
If you need to refer to the generated classes from your own code (e.g. for unit testing), then you cannot use the MSBuild option, and should use the Extension throughout.