简体   繁体   English

从nuget dll中引用文件

[英]Referencing a file from within nuget dll

I have a class library which I want to expose as a nuget package. 我有一个要作为nuget包公开的类库。

The class library I am creating, deserializes a couple of XML files and expose them as properties. 我正在创建的类库反序列化几个XML文件,并将它们公开为属性。 So I am adding these xml files in the nuspec file: 所以我将这些xml文件添加到nuspec文件中:

<files>     
    <file src="..\config1.xml" target="Content\Config" />
    <file src="..\config2.xml" target="Content\Config" />
  </files>

so that the dll can read these files and expose them as properties to the consuming code. 以便dll可以读取这些文件,并将其作为属性公开给使用的代码。

The problem is when I install this NuGet package, the dll is unable to access these XML files. 问题是当我安装此NuGet程序包时,dll无法访问这些XML文件。

What is the right way to handle this use case? 处理此用例的正确方法是什么? To create the NuGet package? 要创建NuGet包?

Assuming the XML file is included in your project, you can set the Build Action property of the XML file to "Embedded Resource". 假设XML文件包含在您的项目中,则可以将XML文件的“ 构建操作”属性设置为“嵌入式资源”。 This says that: 这样说:

The file is passed to the compiler as a resource to be embedded in the assembly. 该文件作为要嵌入到程序集中的资源传递给编译器。

See this post for more details. 有关更多详细信息,请参见这篇文章

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

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