'Can't use Html.Raw on cshtml file in wpf desktop aplication

I'm trying to make .pdf files in WPF desktop app. The process is composed by three steeps:

  1. Make cshtml
  2. Use razor to get HTML with data
  3. Use iText7 to transform HTML file to pdf file.

The problem is that now i need to do a recursive function that writes HTML code and i can't use HTML.raw on cshtml cause it seems like can't use System.Web.Mvc

The code i use is:

var result = Engine.Razor.RunCompile(Resources.GetText(plantilla), 
   plantilla, element.GetType(), element);

using(FileStream pdfDesti = File.Open(desti, FileMode.OpenOrCreate))
{
      ConverterProperties converterProperties = new ConverterProperties();

      HtmlConverter.ConvertToPdf(result, pdfDesti, converterProperties);
}

My app.config include this:

<system.web>
   <compilation debug="true" targetFramework="4.5">
        <assemblies>

            <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.Web.Mvc, Version=5.2.6, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

        </assemblies>
        <pages>
            <namespaces>
                <add namespace="System.Web.Helpers" />
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="System.Web.WebPages" />
            </namespaces>
        </pages>

   </compilation>

</system.web>

And intellisense let me put on top "using System.Web.Mvc" but then, when i run the program, razor says basicly that razorCompiler needs an assembly reference for use MVC

El tipo o el nombre del espacio de nombres 'Mvc' no existe en el espacio de nombres 'System.Web' (¿falta una referencia de ensamblado?)


I have installed the following packages:

  • Microsoft.AspNet.Razor
  • Microsoft.AspNetCore.Mvc.Razor
  • RazorEngine


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source