3

(This is not a duplicate of Print and/or modify the c# version that the razor compiler service uses to compile cshtml because I'm using RazorGenerator, not ASP.NET, the translation from .cshtml to .cs happens every time I press the Save button in Visual Studio, so adding assembly references or NuGet packages to my project won't help)

I have a C# Class Library project using RazorGenerator (a Visual Studio extension that transpiles .cshtml to .cs sources). RazorGenerator itself works fine and my .cshtml files are converted to cs correctly without any problems considering I'm using C# 7.3 language features and types defined in custom assemblies.

The problem is Visual Studio's own .cshtml designer (independent of RazorGenerator) seems to default to the C# 4.0 compiler version and doesn't even load System.Core.dll - so when viewing .cshtml files in the Visual Studio editor I get peppered with error messages that shouldn't be there:

"Feature 'out variable declaration' is not available in C# 4. Please use language version 7.0 or greater."

enter image description here

and broken namespace imports because it isn't loading assemblies:

enter image description here

I saw these SO posts:

...which suggest adding the NuGet Microsoft.CodeDom.Providers.DotNetCompilerPlatform package to the project and restarting Visual Studio, however that did not solve the issue.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • I really wonder, why there is no reaction... Either it is so trivial, that it should be obvious, or nobody knows :-) (Or it's just not possible!) And we don't seem to be the first ones to encounter this annoyance: https://github.com/RazorGenerator/RazorGenerator/issues/177 – Xan-Kun Clark-Davis Apr 30 '19 at 18:19

0 Answers0