How can I retrieve an embedded xml resource?

前端 未结 3 1049
逝去的感伤
逝去的感伤 2020-12-19 12:48

I added an XML file as an embedded resource in my class library by using the accessing the project properties in Visual Studio and then Resources | Add Resource | Add Existi

3条回答
  •  星月不相逢
    2020-12-19 13:19

    I found that this article explains nicely how to set this up: http://www.devx.com/dotnet/Article/10831/1954

    One thing that may have helped in this case is using a different method for determining the location of the embedded resource.

    • GetEntryAssembly: Use this method to reference the executable file that was run to start the current process. The entry assembly is set for Windows forms applications, but for most other applications (for example, web projects), GetEntryAssembly returns 'nothing' (or null, in C#).
    • GetExecutingAssembly: Use this method to reference the same assembly that the executing code is in.
    • GetCallingAssembly: Use this method to reference the assembly containing the code that called the current method. This method is useful if you write generic code to read embedded resources that is inside a shared assembly where the embedded resource is in the calling assembly.

    I personally prefer this method over using the "Resources" tab because it allows me to use other tools to add resources to the project for inclusion on compilation. I don't have to use the GUI with this tool

提交回复
热议问题