This project is read-only.

RazorGenerator - View already defines a member error

Jul 3, 2014 at 4: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.
Jul 3, 2014 at 5: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 7:44 PM
Edited Jul 3, 2014 at 7: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.
Jul 3, 2014 at 9: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.
Jul 3, 2014 at 9: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 9: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
Jul 3, 2014 at 9: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.