在类库项目资源

编程入门 行业动态 更新时间:2024-10-25 10:23:10
本文介绍了在类库项目资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想一些XML文件作为资源添加到我的类库项目。 任何想法如何做到这一点的,后来打电话吗? 在Windows应用程序中,我会做这样 ClassLibrary1.Properties.Resources.file.xml

不过,这并没有任何工作的想法我怎么在这里?

解决方案

本文解释使用嵌入的资源在C#。

它归结为

  • 在设计时间:将文件添加到项目并将其标记为嵌入的资源(属性)
  • 在运行时间:获得大会的情况下,保存你想要的资源,然后让该资源作为一个流
  •   

    VAR组装= Assembly.GetExecutingAssembly();

         

    VAR流= _assembly.GetManifestResourceStream(fully.qualified.name.of.the.resource);

    如果你正在努力制定出资源的FQ名字,一个偷懒的办法是使用的反射来打开保存它的组件。转到资源文件夹,右键单击特定资源,选择复制。

    I want to add some xml file as resource to my class library project . Any idea how to do so , and call it later? In windows application i would do it like ClassLibrary1.Properties.Resources.file.xml

    But here it didn't worked any idea how i do it here ?

    解决方案

    This article explain how to use embedded resources in C#.

    It boils down to

  • At 'Design time': Add file to project and mark it as an embedded resource (properties)
  • At 'Run time': Get instance of Assembly that holds the resource you want, then get that resource out as a stream.
  • var assembly = Assembly.GetExecutingAssembly();

    var stream = _assembly.GetManifestResourceStream("fully.qualified.name.of.the.resource");

    If you're struggling to work out the fq name of the resource, a lazy way is to use the reflector to open the assembly that holds it. Go to the Resources folder, right click on the particular resource and choose 'Copy'.

    更多推荐

    在类库项目资源

    本文发布于:2023-11-13 06:39:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1583724.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:类库   项目   资源

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!