1. Home
  2. Docs
  3. Getting Started
  4. Installation
  5. .NET 6 Installation

.NET 6 Installation

With .NET 6 or core installation, there are some additional steps to get dotnet Report running locally in your project.

It’s always a good idea to check-in your code before adding the dotnetreport NuGet package.

Step 1: Update Project and get files loally

The dotnetreport installation NuGet package adds a bunch of files to your project, however by default they are added as a reference to the NuGet folder instead of being copied inside the project folder. To add them in the right path, edit your project file and add GeneratePathProperty= “true” to the dotnetreport package reference.

Next, add the following to your project to copy front end files included in your project directly rather than as a reference.

  <PropertyGroup>
    <ContentFilesPath>$(PkgdotNetReport)\contentFiles\any\any\</ContentFilesPath>
  </PropertyGroup>
  <Target Name="CopyDotNetReportContent" BeforeTargets="PreBuildEvent">
	<Copy SourceFiles="$(ContentFilesPath)gulpfile.dotnetreport.js" DestinationFiles="$(ProjectDir)\gulpfile.dotnetreport.js"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)package.dotnetreport.json" DestinationFiles="$(ProjectDir)\package.dotnetreport.json"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Content/img/report-logo.png" DestinationFiles="$(ProjectDir)\Content/img/report-logo.png"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Scripts/dotnetreport.js" DestinationFiles="$(ProjectDir)\Scripts/dotnetreport.js"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Scripts/dotnetreport-helper.js" DestinationFiles="$(ProjectDir)\Scripts/dotnetreport-helper.js"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Scripts/dotnetreport-setup.js" DestinationFiles="$(ProjectDir)\Scripts/dotnetreport-setup.js"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Content/dotnetreport.css" DestinationFiles="$(ProjectDir)\Content/dotnetreport.css"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Jobs/DotNetReportJob.cs" DestinationFiles="$(ProjectDir)Jobs/DotNetReportJob.cs"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Models/DotNetReportModel.cs" DestinationFiles="$(ProjectDir)Models/DotNetReportModel.cs"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Controllers/DotNetReportApiController.cs" DestinationFiles="$(ProjectDir)Controllers/DotNetReportApiController.cs"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Controllers/DotNetReportController.cs" DestinationFiles="$(ProjectDir)Controllers/DotNetReportController.cs"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Controllers/DotNetSetupController.cs" DestinationFiles="$(ProjectDir)Controllers/DotNetSetupController.cs"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/DotNetReport/Dashboard.cshtml" DestinationFiles="$(ProjectDir)Views/DotNetReport/Dashboard.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/DotNetReport/Index.cshtml" DestinationFiles="$(ProjectDir)Views/DotNetReport/Index.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/DotNetReport/Report.cshtml" DestinationFiles="$(ProjectDir)Views/DotNetReport/Report.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/DotNetReport/ReportPrint.cshtml" DestinationFiles="$(ProjectDir)Views/DotNetReport/ReportPrint.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/DotNetSetup/Index.cshtml" DestinationFiles="$(ProjectDir)Views/DotNetSetup/Index.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/Shared/_Layout.Report.cshtml" DestinationFiles="$(ProjectDir)Views/Shared/_Layout.Report.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/Shared/_DotnetReportHeaderPartial.cshtml" DestinationFiles="$(ProjectDir)Views/Shared/_DotnetReportHeaderPartial.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/Shared/_DotnetReportJsLibrariesPartial.cshtml" DestinationFiles="$(ProjectDir)Views/Shared/_DotnetReportJsLibrariesPartial.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Views/Shared/_DotnetReportTemplatesPartial.cshtml" DestinationFiles="$(ProjectDir)Views/Shared/_DotnetReportTemplatesPartial.cshtml"></Copy>
	<Copy SourceFiles="$(ContentFilesPath)Startup.cs" DestinationFiles="$(ProjectDir)Startup.cs"></Copy>
  </Target>

$(PkgdotNetReport_core)\contentFiles\any\any\

Next, build the project, don’t worry about errors, but you should notice that the references are gone, and these files are now part of the project.

Finally, remove the entire CopyDotNetReportContent block, otherwise the project will keep overwriting your file changes. We don’t need it anymore.

Step 2: Build Client Side Libraries using NPM and Gulp

Client-side packages need to be added to your package.json file.

The list of libraries dotnet Report uses from npm is included package.dotnetreport.json. Please manually merge the contents into your project’s actual package.json. If you don’t have one, just rename this file to package.json.

After merging, right-click on package.json file in Visual Studio and click “Restore Packages”, or run the following in your command line:

npm install

Then run gulpfile.dotnetreport.js (merge it in with your gulpfile, if you don’t have one, just rename this file to gulpfile.js).

You can run the gulp file by right clicking on it in Visual Studio and choose “Task Manager”. Then run the ‘scripts’ gulp task.

If you don’t see any of the tasks and have only just added the file or a task to the file. You may need to click the refresh button.

To run a task, simply right click it and then choose Run.

Step 3: Update Program.cs

For .NET 6, you have to add the following 2 lines to Program.cs manually:

    Startup.StaticConfig = builder.Configuration; //<--- Add this line manually
    JobScheduler.Start(); //<--- Add this line manually if you want to run scheduled jobs from your app

For .NET core, you have to add a couple of lines manually to your Startup.cs file:

public Startup(IConfiguration configuration)
{
    Configuration = configuration;
    StaticConfig = configuration; //<--- Add this line manually
}
 public IConfiguration Configuration { get; }
 public static IConfiguration StaticConfig { get; private set; }  //<--- Add this line manually

If your project is not using controller with Views, you would also need to add Controller with Views. For .NET core, you would also need to set NewtonSoft Json setting in your Startup.cs.

    services.AddControllersWithViews()
            .AddNewtonsoftJson(options => options.UseMemberCasing()); // <-- This is important otherwise javascript calls won't work

Finally, the last thing is to add the dotnet report keys to your appsettings.json file:

"dotNetReport": {

    "apiurl": "https://dotnetreport.com/api",
    "accountApiToken": "Your Account API Key",
    "dataconnectApiToken": "Your Data Connect Key",
    "privateApiToken": "Your Private API Key"

  },

  "ConnectionStrings": {
    "ConnectionKey": "Data Source=;Initial Catalog=;User ID=;Password=;"
  },

After this, you should be able to build and run the project!

How can we help?