简体   繁体   English

从WPF项目创建单个Exe文件

[英]Create single Exe file from WPF project

Is it possible to create single exe file from my C# WPF project? 是否可以从C#WPF项目创建单个exe文件? The project contains some images and videos in Movies folder inside bin. 该项目在bin中的Movies文件夹中包含一些图像和视频。

How can I compile all of this in singe exe file? 如何在singe exe文件中编译所有这些文件? I know it will be large in size but it is OK. 我知道尺寸会很大,但是还可以。

You should add this files to you project and use Build Action: Resource for this files. 您应该将此文件添加到项目中,并为此文件使用“ Build Action: Resource ”。 In this case, it will be introduced into the main assembly of application. 在这种情况下,它将被引入到应用程序的主程序集中。

It will be a binary resource, because it is embedded in the compiled assembly as an opaque binary large object. 这将是一个二进制资源,因为它作为不透明的二进制大对象嵌入到已编译的程序集中。

Quote from Matthew MacDonald book: Pro WPF 4.5 in C# : 引用Matthew MacDonald book: Pro WPF 4.5 in C#

There are a couple of things that you must not do in order to use assembly resources successfully: 为了成功使用程序集资源,您必须做几件事:

  • Don't make the mistake of setting the Build Action property to Embedded Resource . 不要把将Build Action属性设置为Embedded Resource的错误。 Even though all assembly resources are embedded resources by definition, the Embedded Resource build action places the binary data in another area where it's more difficult to access. 即使所有程序集资源按照定义都是嵌入式资源,“嵌入式资源”构建操作也会将二进制数据放置在更难以访问的另一个区域中。 In WPF applications, it's assumed that you always use a build type of Resource. 在WPF应用程序中,假定您始终使用资源的构建类型。

  • Don't use the Resources tab in the Project Properties window. 不要使用“项目属性”窗口中的“ Resources tab WPF does not support this type of resource URI. WPF不支持这种类型的资源URI。

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

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