lkosson / reportviewercore

Recompilation of Microsoft.ReportViewer for .NET Core 3.1+
402 stars 119 forks source link

Target .net standard 2.0? #182

Closed Mek7 closed 3 months ago

Mek7 commented 5 months ago

Hello, this library now targets the specific .NET versions such as .NET 5, 6, 7, 8. If we want to reference it in a class library project, we will have to target .NET 8 as well, but for class libraries, .net standard is the recommended target. Can your library target .net standard instead of the specific .NET versions?

lkosson commented 5 months ago

Hi. From preliminary experiments - it might be possible. I'm not sure how to deal with Microsoft.CodeAnalysis.VisualBasic references, though.

lkosson commented 5 months ago

There are two major problems when referencing .NET Standard - version-dependent references for Microsoft.CodeAnalysis.VisualBasic and no support for assembly unloading.

I have made some minor changes to allow compilation against .NET Standard 2.1 for Microsoft.ReportViewer.ProcessingObjectModel, Microsoft.ReportViewer.DataVisualization, Microsoft.ReportViewer.Common and Microsoft.ReportViewer.NETCore projects. Microsoft.ReportViewer.WinForms is completely out of scope because WinForms is not available in .NET Standard. Those changes disable dynamic assembly unloading, which means each report invocation will leak some memory.

If that's OK with you, change TargetFrameworks property of above mentioned projects to netstandard2.1 and build custom version of this package. You might also need to tweak Microsoft.CodeAnalysis.VisualBasic reference to match those of your product, bump up System.Drawing.Common version to 8.0 and remove System.Windows.Extensions reference.

Mek7 commented 5 months ago

Thanks for your quick response. I will have to live with that my library also has to target a specific .NET version instead of .netstandard.

ryanryanorient commented 5 months ago

Support for .NET Standard is great, and while .NET 2.1 requires .NET 5+, I wish it would support .NET 2.0 so that it is better compatible with the .NET Framework

lkosson commented 5 months ago

For .NET Framework there is original Report Viewer.

Mek7 commented 5 months ago

Sure, but not when you want to migrate from .NET Framework to .NET. Then, .NET Standard 2.0 is the only bridge between the two, where assemblies targeting .NET Standard 2.0 can be referenced from both.

lkosson commented 5 months ago

Fair enough. The problem is .NET Standard 2.0 is missing some APIs from System.Drawing namespace and don't support AssemblyLoadContext. In principle it might be possible to target .NET Standard 2.0 with ReportViewerCore, but that would require some tedious work for questionable gains.

Consider multi-targeting your assembly/package and compile it against .NET Framework and .NET from same codebase, but referencing ReportViewer and ReportViewerCore respectively.

Mek7 commented 3 months ago

I went a different way - isolated the report rendering into a special web api application that renders the report and returns a byte array - so other code now has no direct references to the code that uses this library. Yes, I also multi-targeted some of the other projects in my solution, because of Entity Framework, but that's a different story... So I am closing this.