Visual Studio - File Properties (Build Action, Copy to Output Directory)

Ref: MSDN (https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/0c6xyb66(v=vs.100) )

Difference between Build action content and ‘Copy to output directory‘ in Visual Studio

Question:

In my project in Visual Studio, I have files that I want included in the output, but not compiled or embedded.

I am aware that there are 2 ways to accomplish this.

  1. Setting the Build Action for the file to ‘Content‘
  2. Setting the ‘Copy to Output Directory‘ to ‘Copy Always‘ or ‘Copy if newer‘

Can someone tell me what the difference is and which scenario is each of the options appropriate for?

Answer:

When setting the Build Action to Content, the file will not be compiled and will be put in the Content output group.

Whether the file gets copies or not depends on the Copy to Output Directory setting at that point.

Of course, if you set Copy Always on a file, it may get compiled and then copied.

See File Properties on MSDN:

------------------------------------------------------------------------------

Build Action Property

The Build Action property indicates what Visual Studio does with a file when a build is executed. Build Action can have one of several values:

  • 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.
  • Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
  • Embedded Resource - This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files.

    Note

    The Build Action property is extensible. As a result, you may see additional options listed for this property that have been added by other products and features.

The default value for Build Action depends on the extension of the file that you add to the solution. For example, if you add a Visual Basic project to Solution Explorer, the default value for Build Action is Compile. This is because the extension .vb indicates a code file that can be compiled. File names and extensions appear in Solution Explorer.

Note that the name of the file in your project will not be the identifier for the managed resource in the assembly manifest (see Assembly Manifest for more information). The identifier will be namespace.filename.extension, where namespace is the value of the DefaultNamespace property in a Visual C# project or RootNamespaceproperty in a Visual Basic project. Filename and extension remain the same as their original designation. If the file is a .resx file, the project system will run resgen.exe on the file, creating a .resource file. The .resource file will be embedded in the assembly. Therefore, the assembly manifest will refer to the .resources file and not the .resx file.

For example, if you add the file MyFile.bmp to a project whose default namespace is MyProj, and set the build action to Embedded Resource, MyProj.MyFile.bmp will be the identifier in the assembly manifest. If you then add the file MyFile.resx to the project, the default build action will be Embedded Resource and MyProj.MyFile.resources will be the identifier in the assembly manifest.

Note that when the resource editor adds an image, it sets Build Action to None, because the .resx file references the image file. At build time, the image is pulled into the .resources file created out of the .resx file. The image can then easily be accessed by way of the strongly-typed class auto-generated for the .resx file. Therefore, you should not change this setting to Embedded Resource, because doing this would include the image two times in the assembly.

For more information about how to access resource files (compiled from .resx files) at run time, see ResourceManager. For more information about how to access all other embedded files and resources at run time, see GetManifestResourceStream.

Copy to Output Directory Property

This property specifies the conditions under which the selected source file will be copied to the output directory. Select Do not copy if the file is never to be copied to the output directory. Select Copy always if the file is always to be copied to the output directory. Select Copy if newer if the file is to be copied only when it is newer than an existing file of the same name in the output directory.

For information about changing the output directory, see Build Page, Project Designer (C#) or Compile Page, Project Designer (Visual Basic).

Note

In smart device projects, the newness of a .dll or .exe file is determined by comparing the Win32 versions as follows:

If the device-side version is less than that of the desktop, the file is copied.

If the device-side version is greater than that of the desktop, the file is not copied.

If the versions are the same, a checksum comparison is made. If the checksums are the same, the file is not copied. If the checksums are different, the file is copied.

The newness of files other than .dll and .exe is based only on checksum.

Note

Data files will be copied to a subfolder named Data Files in the output directory.

原文地址:https://www.cnblogs.com/frankcui/p/10774799.html

时间: 2024-08-29 22:51:03

Visual Studio - File Properties (Build Action, Copy to Output Directory)的相关文章

Visual Studio中的Build和Rebuild区别

Visual Studio中的Build和Rebuild区别 一般来说Rebuild=99%*(Clean+Build),效果在非常小的可能性下会不同,一般可以忽略.Rebuild是对Solution下的所有项目,逐个进行 Clean+Build.不论文件更改与否Clean+Build是对选中的项目(如果选中Solution的话,全部Clean之后,再全部Build)先执行Clean再执行Build.一般不需要执行Clean.Build只是针对有更改过的文件进行编译.而Rebuild会编译所有.

Visual Studio配置MySql数据库

MySQL Connector/C++ is available as a static or dynamic library to use with your application. This section describes how to link the library to your application. MySQL Connector/C++能做为项目的静态或动态库,这章节就是描述如何链接该库到你的项目中. Note To avoid potential crashes, th

Visual Studio Support (DDEX)

原文 VS2012,VS2013,and VS2015Pro+NpgsqlDdexProvider+EFv6 how to(by @kenjiuno) Reference: #213 Overview Install Npgsql DDEX (Data Designer Extensibility) provider. Install Npgsql ADO.NET Data Provider. Visual Studio’s Entity Data Model wizard will be en

Recommended add-ons/plugins for Microsoft Visual Studio [closed]

SmartPaster - (FREE) Copy/Paste code generator for strings AnkhSvn - (FREE) SVN Source Control Integration for VS.NET VisualSVN Server - (FREE) Source Control ReSharper - IDE enhancement that helps with refactoring and productivity CodeRush - Code ge

Visual Studio解决方案的目录结构设置和管理

摘至:http://blog.csdn.net/lp310018931/article/details/47991759 首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件夹以及解决方案和各个项目对应的配置文件包含关系,假设新建一个项目ssyy,解决方案起名fangan,注意解决方案包括项 目,此时生成的最外层目录为fangan代表整个解决方案的内容都在这个文件夹内.在这个fangan文件夹内包含有fangan.sln的解决方案配置 文件和一个ssyy文件夹,ssyy

Visual Studio 要求导入 pfx 密钥以及导入后依然要求导入的解决办法

本文为个人博客备份文章,原文地址: http://validvoid.net/visual-studio-pfx-import/ 导入密钥 在使用 Visual Studio 生产项目时,使用 pfx 密钥签名的项目可能遭遇以下问题: 无法导入以下密钥文件: ****.pfx,该密钥文件可能受密码保护.若要更正此问题,请尝试再次导入证书,或手动将证书安装到具有以下密钥容器名称的强名称 CSP: VS_KEY_**************** Cannot import the following

visual studio 2014 新特性

原文如下: Visual Studio "14" CTP Today, we are making available a first community technology preview of the next version of Visual Studio, codenamed Visual Studio "14".  This early build is focused on enabling feedback and testing from the

Visual Studio环境变量、工作目录、vc++目录、 命令等 的配置和作用

在调试 Visual Studio 2008 程序时,经常有一些动态链接库(即 dll 文件)需要加载到工程里,这样才能依赖第三方库进行程序调试. 这些动态链接库,往往都是测试版本或是开发中的版本,或者会有若干个版本:这个时候,如果直接把 dll 所在目录加到 PATH 里,则会有潜在冲突的危险:如果直接拷贝到 Visual Studio 的目录下,假如测试工程太多,每次有新版本的动态链接库更新时,你需要更新若干次,拷贝.粘贴苦不堪言. 在开发过程中,究竟怎样来让 Visual Studio 链

Visual Studio 2012环境变量、工作目录、vc++目录、 命令等 的配置和作用

在调试 Visual Studio 212 程序时,经常有一些动态链接库(即 dll 文件)需要加载到工程里,这样才能依赖第三方库进行程序调试. 这些动态链接库,往往都是测试版本或是开发中的版本,或者会有若干个版本:这个时候,如果直接把 dll 所在目录加到 PATH 里,则会有潜在冲突的危险:如果直接拷贝到 Visual Studio 的目录下,假如测试工程太多,每次有新版本的动态链接库更新时,你需要更新若干次,拷贝.粘贴苦不堪言. 在开发过程中,究竟怎样来让 Visual Studio 链接