在类库项目资源 [英] resources at class library project

查看:122
本文介绍了在类库项目资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

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

它归结为

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

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

  1. At 'Design time': Add file to project and mark it as an embedded resource (properties)
  2. 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'.

这篇关于在类库项目资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆