Visual Studio 中项目文件属性的Build action 设置

本文详细介绍了Visual Studio中项目文件的各种Build Action设置及其用途,包括None、Compile、Content、EmbeddedResource等,并针对WPF应用提供了特定的设置说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • None: The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

  • 无,不进行输出和编译。

  • Compile: The file is compiled into the build output. This setting is used for code files.

  • 编译文件 ,通常为.cs代码文件。

  • Content: Allows you to retrieve a file (in same dir as assembly) as a stream via Application.GetContentStream( uri ). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which VS graciously adds when you mark a file as "Content"

  • 生成为内容,需要设置copy to output directory,从相应的程序目录中去读取此文件。

  • Embedded resource: embeds the file in an exclusive assembly manifest resource.

  • 把文件嵌入到清单资源中,读取方法 http://blog.youkuaiyun.com/kevindr/article/details/46723187

  • Resource (wpf only): embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.

  • (仅用于WPF)将文件嵌入到AppName.g.resources中,

  • Page (wpf only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (i.e. available as `AppName.g.resources)

  • (仅用于WPF)将xaml文件编译为baml文件。 

  • ApplicationDefinition (wpf only): Mark the XAML/class file that defines your application. You specify the code-behind with the x:Class="Namespace.ClassName" and set the startup form/page with StartupUri="Window1.xaml"

  • (仅用于WPF)定义应用程序

  • SplashScreen (wpf only): An image that is marked as SplashScreen is shown automatically when an WPF application loads, and then fades

  • (仅用于WPF)

  • DesignData: Compiles xaml viewmodels so that usercontrols can be previewed with sample data in visual studio (uses mock types)

  • (仅用于WPF) 编译xmal viewmodel,以便能够预览

  • DesignDataWithDesignTimeCreatableTypes: Compiles xaml viewmodels so that usercontrols can be previewed with sample data in visual studio (uses actual types)

  • EntityDeploy(Entity Framework)used to deploy the Entity Framework artifacts

  • 用于Entity Framework

  • CodeAnalysisDictionary: A xml file containing custom word dictionary for spelling rules

### 如何在 Visual Studio 2022 中显示文件资源管理器或解决方案资源管理器 #### 显示解决方案资源管理器 为了确保能够在 Visual Studio 2022 中查看项目的结构以及所有关联的文件,可以按照以下方法来打开并配置解决方案资源管理器: - **通过菜单栏访问** 如果当前窗口中未显示解决方案资源管理器,则可以通过顶部菜单依次选择 `视图(View)` -> `解决方案资源管理器(Solution Explorer)` 来激活该面板[^1]。 - **快捷键方式** 使用默认设置下,按下组合键 `Ctrl` + `Alt` + `L` 可迅速调出解决方案资源管理器。此方法适用于希望减少鼠标操作提高效率的情况。 一旦打开了解决方案资源管理器,应该能够浏览整个项目树形结构,并且可以看到已添加至项目的各种类型的文件(如C++头文件、源码文件等)。对于某些特定情况下未能正常加载或显示的文件,可能是因为它们被标记为不可见或者是由于构建动作设置不当所致[^2]。 针对 WPF 类型的应用程序,在遇到图像无法正确呈现的问题时,除了确认这些媒体文件确实存在于预期路径之外,还需要检查其属性中的“生成操作(Build Action)”是否设定了合适的选项,比如将其设定成 “Resource”,从而让编译器知道怎样处理这类静态资源[^3]。 ```csharp // 这是一个简单的 C# 示例代码片段用于说明如何读取资源文件 using System; using System.IO; namespace ResourceExample { class Program { static void Main(string[] args) { string resourcePath = @"pack://application:,,,/YourAssemblyName;component/Resources/image.png"; Console.WriteLine($"Image path is {resourcePath}"); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值