question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core v2.1 SDK broke RazorLight in console app

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:44 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
Brandejscommented, Aug 15, 2018

Many thanks.

I think that this line in .csproj solved the issue.

<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

3reactions
kraghavkcommented, Aug 4, 2019

This fixed it for me!

<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found