繁体   English   中英

Blazor 无法在发布时从 class 库加载图像

[英]Blazor can't load image from class library at publish

我有一个包含 PDFGenerator 组件的 Blazor 组件库。 我通过 Blazor 服务器应用程序使用这个库,我必须发送图像路径才能将其添加到 PDF 中。 在开发阶段它工作正常,但在部署到测试服务器后,由于路径而出现错误。
服务器应用:
var Path="..\\BlazorUI\\Blazor.Components\\wwwroot\\Images\\Logo.png"
Blazor 组件库
Image image = section.Headers.Primary.AddImage(ImageSource.FromFile(path));
错误
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Webservice\BlazorUI\Blazor.Components\wwwroot\Images\Logo.png
服务器中Images文件夹的路径:
C:\Webservice\application\wwwroot\_content\Blazor.Components\Images
我的问题:
如何使用动态路径在开发阶段和测试服务器中工作?
谢谢

我做了一个临时解决方案:

var path = "";
var publishFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\_content\\Blazor.Components");
 //Publish mode
 if (Directory.Exists(publishFolder))
 {
      path = Path.Combine(publishFolder, restPath);
 }
 //development mode
 else
 {
     path = Path.Combine("..\\BlazorUI\\Blazor.Components\\wwwroot\\", restPath);
 }
 Image image = section.Footers.Primary.AddImage(ImageSource.FromFile(path));

笔记
发布后:此路径_content/Blazor.Components/Images已在服务器主应用程序文件夹的wwwroot内创建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM