Using RazorGenerator in a WinRT project

May 9, 2012 at 6:41 AM

I am producing some HTML content for the share charm in WinRT.  So I need to precompile the cshtml to .cs in my WinRT project.  I'm not entirely clear over the entire process that needs to be used here, but as I understand it I need to install the RazorGenerator visual studio extension. Unfortunately I can only install that into visual studio 2010?

How do I get it installed into visual studio 2011, so that I can select a custom tool of RazorGenerator?

Secondly RazorGenerator.Templating isn't able to be installed in a WinRT project.  So I decompiled the class and I can build that class, but there are some changes required in the write function.  It should look like this:

public void Write(object value)
{
    if (value == null)
        return;
#if NETFX_CORE
    MethodInfo method = null;

    var methods = value.GetType().GetTypeInfo().GetDeclaredMethods("ToString");

    if (methods != null)
    {
        foreach (MethodInfo methodInfo in methods)
        {
            if (methodInfo.GetParameters().Count() == 1 && methodInfo.GetParameters()[0].ParameterType == typeof (IFormatProvider))
            {
                method = methodInfo;
            }
        }
    }
#else
    MethodInfo method = value.GetType().GetMethod("ToString", new Type[1]
{
typeof (IFormatProvider)
});
#endif
    string textToAppend;
    if (method == (MethodInfo)null)
        textToAppend = value.ToString();
    else
        textToAppend = (string)method.Invoke(value, new object[1]
{
    (object) CultureInfo.InvariantCulture
});
    this.WriteLiteral(textToAppend);
}

And then it works fine.  Hopefully a WinRT specific version of the nuget project can be built at some point, but in the meantime if I include that class myself, I will be fine. Is just a matter of getting the razor generator functioning.  Hope someone is able to help with that.

Thanks,

Stefan

May 9, 2012 at 6:41 AM

Why does my code look so terrible?  I inserted it using the insert code feature....

Coordinator
May 9, 2012 at 5:23 PM

I really need to get to checking out the pull request \ discussion about making the vsix work in Dev11. I'll give that a shot today eve. We could probably simplify the Write method to work in WinRT and 4.0 - we basically stole the method from T4 templates, but there isn't a reason we could use something that works under both runtimes.

Coordinator
May 9, 2012 at 5:23 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.