.NET Core v2.1 SDK broke RazorLight in console app
See original GitHub issueI was using RazorLight fine in VS2017 with .NET Core 2.0. I’ve tested to upgrade to .NET Core 2.1 SDK (so it’s building using .NET Core 2.1 RC1, but also tested with the release of 2.1, same issue) and that broke my console app when calling CompileRenderAsync. It still works if I call this from a ASP.NET Core project type (which is targeting .NET Core 2.0). I have PreserveCompilationContext in the csproj set to true, but still getting this:
Failed to compile generated Razor template:
- (3:35) The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
- (3:63) Predefined type 'System.String' is not defined or imported
- (3:76) Predefined type 'System.Type' is not defined or imported
- (3:10) Predefined type 'System.Void' is not defined or imported
- (11:37) The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
(and 100s more of these)
I saw this issue, but I’m not 100% sure it’s related: https://github.com/dotnet/sdk/issues/2092. To me it seems something in the build process has changed, but I don’t know if it’s a known issue or if there is a fix.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:44 (6 by maintainers)
Top Results From Across the Web
What is the best way to use Razor in a console application
Everything seems to work with the least trouble if create and consume your Razor files in a .NET Core console app. You can...
Read more >RazorLight
NET SDK tools ship with bad MSBuild targets that somehow don't "preserve compilation context" and you need an immediate fix while waiting for...
Read more >PreserveCompilationContext not configured by default - .NET
Learn about the breaking change in ASP.NET Core 6.0 where the PreserveCompilationContext property is no longer configured by default.
Read more >Render Emails Using Razor Templating
Learn how to use different open-source Razor engines to render Razor templates to strings for sending emails.
Read more >How to publish .NET console app to single independent . ...
NET Core 3.x a single-file application would extract itself to a temporary folder and launch itself. This was a quick and dirty way...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Many thanks.
I think that this line in .csproj solved the issue.
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
This fixed it for me!
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>