简体   繁体   English

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

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

I have a Blazor component libary that has a PDFGenerator component.我有一个包含 PDFGenerator 组件的 Blazor 组件库。 I consume this library by Blazor server application, I have to send path of image to add it in the PDF.我通过 Blazor 服务器应用程序使用这个库,我必须发送图像路径才能将其添加到 PDF 中。 In development stage it works fine but after deploying to test server I get an error becuase of the path.在开发阶段它工作正常,但在部署到测试服务器后,由于路径而出现错误。
Server application:服务器应用:
var Path="..\\BlazorUI\\Blazor.Components\\wwwroot\\Images\\Logo.png"
Blazor component libaray Blazor 组件库
Image image = section.Headers.Primary.AddImage(ImageSource.FromFile(path));
Error错误
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Webservice\BlazorUI\Blazor.Components\wwwroot\Images\Logo.png
The path of the Images folder in the server:服务器中Images文件夹的路径:
C:\Webservice\application\wwwroot\_content\Blazor.Components\Images
My question:我的问题:
How can I use dynamic path to work in development stage and also in the test server?如何使用动态路径在开发阶段和测试服务器中工作?
Thanks谢谢

I made a temporary solution:我做了一个临时解决方案:

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));

Note笔记
After publishing: this path _content/Blazor.Components/Images has been created inside wwwroot of the main application folder in the server.发布后:此路径_content/Blazor.Components/Images已在服务器主应用程序文件夹的wwwroot内创建。

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

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