New to Telerik Reporting? Download free 30-day trial

Мigrate ASP.NET Core project from .NET Framework to .NET

Environment

Product Progress® Telerik® Reporting
Project Type ASP.NET Core targetting the full .NET Framework

Description

Starting with Telerik Reporting R1 2019, we support report rendering runtime targeting .NET Standard 2.0 and the .NET Core 2.1+ and .NET 5+ applications that are compatible with it. For more information how to use reports in .NET/.NET Core/.NET Standard application for Windows and Linux platforms, please refer to .NET Core Support help article.

Prior to that, the only available workaround was to switch the .NET Core application's target framework to full .NET Framework.

Now, how to migrate the existing ASP.NET Core project from full .NET Framework back to .NET or .NET Core? In this article we would show you step-by-step and we would assume that the Telerik Rest Service is configured within that application (hosted on the same domain).

Solution

  1. Unload the project and edit .csproj file's setting

    <TargetFramework>netcoreapp2.2</TargetFramework>
    

    and reload it back.

    The above setting is for .NET Core 2.2. Change it correspondingly for the other target frameworks.

  2. Remove the old Telerik libraries. The new Telerik Reporting libraries for .NET Core projects are available through Telerik NuGet private feed - Telerik Reporting NuGet packages.

  3. Update Microsoft.AspNetCore libraries to newer version (if needed).
  4. Application configuration in ASP.NET Core uses the new SDK-style project and utilizes appsettings.json as a configuration file. The ConnectionStrings setting should be configured in JSON-based format like for example:

    //appsettings.json
    //Supported ConnectionStrings section configurations:
    "ConnectionStrings": {
        //This connection string will use System.Data.SqlClient as data provider invariant name.
        //"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
    
        //This connection string explicitly states the data provider invariant name - mandatory for databases other than MSSQL Server.
        "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
            "connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
            "providerName": "System.Data.SqlClient"
        }
    }
    
    //This type of connection string configuration is also supported.
    //"ConnectionStrings": [
    //  {
    //      "name": "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString",
    //      "connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
    //      "providerName": "System.Data.SqlClient"
    //  }
    //]
    
  5. In order to load the configuration from the appsettings.json file, an additional instance of type ConfigurationService needs to be created in Startup.cs. This class will add the appsettings.json as configuration file and will be used later in the ReportsController constructor:

    public class ConfigurationService
    {
        public IConfiguration Configuration { get; private set; }
    
        public IHostingEnvironment Environment { get; private set; }
        public ConfigurationService(IHostingEnvironment environment)
        {
            this.Environment = environment;
    
            var configFileName = System.IO.Path.Combine(environment.ContentRootPath,"appsettings.json");
            var config = new ConfigurationBuilder()
                            .AddJsonFile(configFileName, true)
                            .Build();
    
            this.Configuration = config;
        }
    }
    

Notes

A sample demo can be downloaded from the Reporting-Samples GitHub repository.

In this article