Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent class to HtmlTextWriter in dotnet core/corefx?

Many libraries that create html rely on HtmlTextWriter. Is there an equivalent to this class in the new corefx?

Here are a few projects that rely on HtmlTextWriter: https://github.com/darthfubumvc/htmltags https://fluenttags.codeplex.com/

An alternative question might be: "What is the best way to generate html using dotnet core / corefx?"

like image 271
Chris Weber Avatar asked Dec 09 '15 17:12

Chris Weber


People also ask

Is .NET Core in C#?

NET Core platform such as mobile, desktop, web, cloud, IoT, machine learning, microservices, game, etc. Supports Multiple Languages: You can use C#, F#, and Visual Basic programming languages to develop .

What is HtmlTextWriter?

HtmlTextWriter writes HTML. It allows you to generate a list of HTML elements, such as div elements. You could use StringBuilder, but HtmlTextWriter is sometimes better. Notes, HTML. It is easy to generate HTML using StringBuilder, just like any other string.

What is .NET Core used for?

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. With ASP.NET Core, you can: Build web apps and services, Internet of Things (IoT) apps, and mobile backends. Use your favorite development tools on Windows, macOS, and Linux.

Can I use .NET Core and .NET framework together?

At this point, if your NuGet dependencies are compatible with both your netcore and netframework targets you may be done! The big news here is that most of your NuGet dependencies are compatible with both. All of the most downloaded NuGet packages are either multi-targeted, or have packages for each target.


2 Answers

There's a super easy fix that I've tested working on .NET core 3.1 and .NET 5. Just install NuGet package HtmlTextWriter in your .NET core project and that's it.

like image 193
bobt Avatar answered Oct 09 '22 14:10

bobt


.NET Core 2.0 does not support HtmlTextWriter class.

You could work around this by moving your logic, which uses HtmlTextWriter, to the class library .NET Standard 2.0. Then you will be able to reference this class library from both - .NET Core and .NET Framework projects.

like image 2
Dmitry Pavlov Avatar answered Oct 09 '22 15:10

Dmitry Pavlov