I am trying to use IRazorViewEngine
in a console application <Project Sdk="Microsoft.NET.Sdk">
(not <Project Sdk="Microsoft.NET.Sdk.Web">
) to render a .cshtml
page in memory. I registered every needed dependency in the ServiceProvider
. While calling the following line I get a CompilationFailedException
:
_viewEngine.GetView(directory, name, true);
Exception:
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
kmcajniq.bah(4,20): error CS0400: The type or namespace name 'Microsoft' could not be found in the global namespace (are you missing an assembly reference?)
kmcajniq.bah(5,19): error CS0400: The type or namespace name 'Microsoft' could not be found in the global namespace (are you missing an assembly reference?)
kmcajniq.bah(4,82): error CS0518: Predefined type 'System.Type' is not defined or imported
kmcajniq.bah(4,115): error CS0518: Predefined type 'System.String' is not defined or imported
kmcajniq.bah(4,132): error CS0518: Predefined type 'System.String' is not defined or imported
kmcajniq.bah(5,81): error CS0518: Predefined type 'System.String' is not defined or imported
and other more missing System
and Microsoft
types.
However, when I'm changing the project sdk to Microsoft.NET.Sdk.Web
everything works fine.
What is Microsoft.NET.Sdk
missing what Microsoft.NET.Sdk.Web
does, that Razor rendering works?