Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 577 forks source link

Template compilation fails when using RoslynCompilerServiceFactory in ASP.NET vNext project #283

Open IsaacSee opened 9 years ago

IsaacSee commented 9 years ago

Hello.

We are using RazorEngine to render email templates in an ASPNET vNEXT project.

Everything works very well when using "dynamic" models, with the default CompilerServiceFactory.

But we are trying to improve things using typed models (types that exists in a vNext project, built with Roslyn) by including RazorEngine.Roslyn and setting the RoslynCompilerServiceFactory.

With the following packages (last pre-release builds availables):

On the following DNX runtime (last pre-release build available):

Doing this, we end up with this exception during template compilation : MissingMethodException: Method not found: 'System .Collections.Immutable.ImmutableArray1 Microsoft.CodeAnalysis.Emit.EmitResult.get_Diagnostics()'.`

We are aware we are living on the edge, but maybe someone else had this issue.

matthid commented 9 years ago

living on the edge

Pretty much, yes :)

I think the problem here is that on DNX another build of Roslyn is loaded (not the same we currently build against => net45) It should be pretty straight forward to add another (portable?) build. Of course we cannot use CodeDOM in that case. Let me know if you want to contribute and if you need some help there. I can setup the basic build in another branch, so you only need to "#ifdef" out some unsupported stuff and it should, in theory, work.

IsaacSee commented 9 years ago

Thanks for your answer :) Yes, if you can setup a branch, pointing me the right direction to take, I'd be glad to try to make this work with the right DNX build.

matthid commented 9 years ago

Ok, I did look into it. Sadly I couldn't find a way to build for "dnxcore50" without VS2015 and "project.json". So it will not integrate nicely in the current build infrastructure anyway... With this in mind, I think the best is to just add a project.json, make it work and look into the integration later... I think once this stuff is all released FAKE/msbuild will support project.json eventually.

If you know a way to make it build via regular project files that would be helpful and I could try again... Otherwise I think the best is to ignore this for now.

matthid commented 9 years ago

To clarify: The problem is that Microsoft.AspNet.Razor (a razorengine dependency) has no portable build compatible with netcore. Instead they have a direct netcore build, which means we need to build against netcore as well... (Another way around would be to rebuild Razor ourself against a portable profile compatible with netcore)

matthid commented 9 years ago

I just saw the same problem after updating to the latest nuget packages, in my case adding assembly redirects helped.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="RazorEngine" publicKeyToken="9ee697374c7e744a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.7.0.0" newVersion="3.7.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces.Desktop" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Composition.AttributedModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Composition.Convention" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Composition.Hosting" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Composition.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Composition.TypedParts" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.30.0" newVersion="1.0.30.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1507.118" newVersion="4.2.1507.118" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Moq.Silverlight" publicKeyToken="69f491c39445e920" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1507.118" newVersion="4.2.1507.118" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.22.0" newVersion="1.0.22.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity.RegistrationByConvention" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
</assemblyBinding>