c#应用程序中的资源和嵌入式资源有什么区别?

时间:2022-03-04 13:21:28

When should I use one or the other?

我什么时候该用一个还是另一个?

I'd like all of the files I use in my app (images, sound, xml file, etc.) to be inside of the .exe file so I don't deploy with a bunch of folders and files.

我希望我在应用程序中使用的所有文件(图像、声音、xml文件等)都在.exe文件中,这样我就不会部署一堆文件夹和文件。

Thanks for the info.

谢谢你的信息。

4 个解决方案

#1


54  

“Resource” and “Content” build actions are to access the WPF resources using the Uris. However “Embedded Resource” is for prior technologies. However both options embeds the resource in assembly but “Resource” option to be used for WPF.

“资源”和“内容”构建操作是使用uri访问WPF资源。然而,“嵌入式资源”适用于以前的技术。但是,这两个选项都将资源嵌入到程序集中,但是WPF使用的“resource”选项。

MSDN privides full explanation here

这里有充分的解释。

#2


4  

A WPF resource (build action = Resource) leverages embedded resources as supported by the core .NET framework, but adds support for accessing the embedded resource via a pack URI. From MSDN:

WPF资源(build action = resource)利用了核心。net框架支持的嵌入式资源,但增加了对通过包URI访问嵌入式资源的支持。从MSDN:

WPF resource files are not the same as the embedded or linked type of resources that can be configured using the core .NET Framework support for assembly resources. While WPF resource files do leverage the core .NET Framework embedded resource support, the ability to access WPF resource files using pack URIs is easier than using namespaces.

WPF资源文件与可使用核心。net框架支持的汇编资源配置的嵌入式或链接类型资源不同。虽然WPF资源文件确实利用了核心的. net框架内嵌的资源支持,但是使用pack uri访问WPF资源文件比使用名称空间更容易。

#3


2  

As reported by MSDN,

据MSDN,

Embedded resources are the best choice if you have to share application resource (.resx) files between multiple projects. For example, if you have a common resource file that contains your company's logos, trademark information, and such, using embedded resources means you have to copy only the .resx file and not the associated resource data files.

如果您必须在多个项目之间共享应用程序资源(.resx)文件,那么嵌入式资源是最佳选择。例如,如果您有一个公共资源文件,其中包含公司的标识、商标信息等,那么使用嵌入式资源意味着您必须只复制.resx文件,而不复制相关的资源数据文件。

You cannot edit embedded resources directly. If you try to edit an embedded resource, you will receive a message prompting you to convert the item to a linked resource in order to edit it. Conversion is recommended but optional. You must export them, make your modifications in an external program, and then import them back into your project.

不能直接编辑嵌入式资源。如果您试图编辑一个嵌入式资源,您将收到一条消息,提示您将项目转换为一个链接资源,以便编辑它。建议转换,但可选。您必须导出它们,在外部程序中进行修改,然后将它们导入到项目中。

#4


0  

Thanks for all the reports, that helped me find more precisely where was the problem: For me, it was the images used as project icon in the task bar that was built as resources and had to be built as content. All others images can be build as resources, no problem.

感谢所有的报告,这帮助我更准确地找到了问题所在:对我来说,它是在任务栏中用作项目图标的图像,它是作为资源构建的,必须作为内容构建。所有其他的图像都可以作为资源来构建,没有问题。

Hope this helps for the future.

希望这对未来有所帮助。

#1


54  

“Resource” and “Content” build actions are to access the WPF resources using the Uris. However “Embedded Resource” is for prior technologies. However both options embeds the resource in assembly but “Resource” option to be used for WPF.

“资源”和“内容”构建操作是使用uri访问WPF资源。然而,“嵌入式资源”适用于以前的技术。但是,这两个选项都将资源嵌入到程序集中,但是WPF使用的“resource”选项。

MSDN privides full explanation here

这里有充分的解释。

#2


4  

A WPF resource (build action = Resource) leverages embedded resources as supported by the core .NET framework, but adds support for accessing the embedded resource via a pack URI. From MSDN:

WPF资源(build action = resource)利用了核心。net框架支持的嵌入式资源,但增加了对通过包URI访问嵌入式资源的支持。从MSDN:

WPF resource files are not the same as the embedded or linked type of resources that can be configured using the core .NET Framework support for assembly resources. While WPF resource files do leverage the core .NET Framework embedded resource support, the ability to access WPF resource files using pack URIs is easier than using namespaces.

WPF资源文件与可使用核心。net框架支持的汇编资源配置的嵌入式或链接类型资源不同。虽然WPF资源文件确实利用了核心的. net框架内嵌的资源支持,但是使用pack uri访问WPF资源文件比使用名称空间更容易。

#3


2  

As reported by MSDN,

据MSDN,

Embedded resources are the best choice if you have to share application resource (.resx) files between multiple projects. For example, if you have a common resource file that contains your company's logos, trademark information, and such, using embedded resources means you have to copy only the .resx file and not the associated resource data files.

如果您必须在多个项目之间共享应用程序资源(.resx)文件,那么嵌入式资源是最佳选择。例如,如果您有一个公共资源文件,其中包含公司的标识、商标信息等,那么使用嵌入式资源意味着您必须只复制.resx文件,而不复制相关的资源数据文件。

You cannot edit embedded resources directly. If you try to edit an embedded resource, you will receive a message prompting you to convert the item to a linked resource in order to edit it. Conversion is recommended but optional. You must export them, make your modifications in an external program, and then import them back into your project.

不能直接编辑嵌入式资源。如果您试图编辑一个嵌入式资源,您将收到一条消息,提示您将项目转换为一个链接资源,以便编辑它。建议转换,但可选。您必须导出它们,在外部程序中进行修改,然后将它们导入到项目中。

#4


0  

Thanks for all the reports, that helped me find more precisely where was the problem: For me, it was the images used as project icon in the task bar that was built as resources and had to be built as content. All others images can be build as resources, no problem.

感谢所有的报告,这帮助我更准确地找到了问题所在:对我来说,它是在任务栏中用作项目图标的图像,它是作为资源构建的,必须作为内容构建。所有其他的图像都可以作为资源来构建,没有问题。

Hope this helps for the future.

希望这对未来有所帮助。