asp.net 核心 3 轮盘启动.cs环境问题



我尝试使用 Rotativa ım 遵循本指南 在"开始"中.cs在"配置函数"中,添加此代码

RotativaConfiguration.Setup(env);
Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' to 'Microsoft.AspNetCore.Hosting.IHostingEnvironment'    

我搜索此错误并找到这个并像这样转换我的代码

RotativaConfiguration.Setup(env.WebRootPath, "Rotativa");

它给了我这个错误

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.AspNetCore.Hosting.IHostingEnvironment'  

在 wwwroot 中添加旋转文件夹并添加 wkhtmltoimage.exe, wkhtmltopdf.exe

我的软件包版本 Rotativa.aspnetcore v1.1.1 使用当前 asp.net 核心版本 3.xx 有什么问题可以解释我?

从Nuget软件包中删除现有的Rotativa.AspNetCore,然后安装测试版:

Install-Package Rotativa.AspNetCore -Version 1.2.0-beta

这其中有重载方法,该方法也适用于IWebHostingEnvironment

安装后,在配置方法中配置为:

RotativaConfiguration.Setup(env.WebRootPath, "Rotativa");

我在statup中找到这样的解决方案.cs在配置函数中添加env2和obsolute

[Obsolete]
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Microsoft.AspNetCore.Hosting.IHostingEnvironment env2)

并像这样更改它

RotativaConfiguration.Setup(env2);

它现在可以工作,但如果你知道更好的解决方案,请描述它。

适用于版本 3.0 和 3.1

// Rotary configuration 
// This is for the rotating to use the files in the Rotating folder
RotativaConfiguration.Setup (env.ContentRootPath, "Rotativa");

安装Install-Package Rotativa.AspNetCore -Version 1.2.0-beta

将 Rotativa 环境变量设置为RotativaConfiguration.Setup(env.WebRootPath, "/usr/bin/");

如果您使用的是 Ubuntu 20.10 或 20.04,请安装 wkhtmlpdf。sudo apt install wkhtmlpdf

这适用于 Dot Net Core 3.1 或 5.0,我已经测试过了两者。

最新更新