简体   繁体   English

从被称为.dll文件的库中加载图像

[英]Load images from libraries referenced as .dll files

I'm doing research and prototyping at my internship, and my topic is whether it's possible to use a Blazor library compiled as a dll (as opposed to referencing the library as a project). 我正在实习期间进行研究和制作原型,我的主题是是否可以使用将Blazor库编译为dll(而不是将库作为项目引用)。

Specifically I am meant to focus on content such as css and images, which seems to be a problem when accessing from a dll in general. 具体来说,我的意思是专注于CSS和图像等内容,这通常在从dll访问时似乎是一个问题。

My structure is as follows: 我的结构如下:

SampleApp references SampleLibrary, which has an image in its content folder. SampleApp引用SampleLibrary,其内容文件夹中有一个图像。 The image is set to be an embedded resource, so it should be included in the dll. 该图像设置为嵌入式资源,因此应包含在dll中。

I'm now trying to access the file via img-tag, but I can't find a way to give a correct path to reference in the SampleApp, let alone the SampleLibrary itself. 我现在正在尝试通过img-tag访问文件,但是我找不到在SampleApp中提供正确引用路径的方法,更不用说SampleLibrary本身了。

Did anyone find a way to reference image paths from dlls like that? 有没有人找到一种从dll引用图像路径的方法?

Create a Blazor class library (dotnet new blazorlib) including your resources, which allows you to share the code in a NuGet package. 创建一个Blazor类库(dotnet新blazorlib),其中包括您的资源,该库可让您共享NuGet包中的代码。 The Blazor class library handles embedding the image resources in the built assembly. Blazor类库处理将图像资源嵌入到生成的程序集中。 The image files are placed in the wwwroot folder, and the tooling takes care of embedding the resources when the library is built. 图像文件放置在wwwroot文件夹中,该工具负责在构建库时嵌入资源。 The built NuGet package is referenced in the project file of a Blazor app just as any normal NuGet package is referenced. 就像引用任何普通的NuGet包一样,在Blazor应用程序的项目文件中也会引用构建的NuGet包。 After the app has been restored, app code can reference the image files... 恢复应用程序后,应用程序代码可以引用图像文件...

Hope this helps... 希望这可以帮助...

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

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