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.

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

  1. Visual Studio中的“build”、“rebuild”、“clean”的区别

    区别 rebuild基本相当于clean+build build只针对修改过的文件进行编译,rebuild会对所有文件编译(无论是否修改). clean 删除中间和输出文件,中间文件是指一些生成应用的 ...

  2. Visual Studio中的Build Event

    在VS中,进行build时,可以在build之前,或者之后执行一些操作,比如把一些css,font,images文件从一个项目的文件夹复制到另一个项目的文件夹 方法: 点击项目,右键-属性-Build ...

  3. Visual studio C#语言输出调试信息到Output窗口方法

    1.菜单栏: 工具>选项>调试>将所有输出窗口文本重定向到即时窗口          2.使用Console.WriteLine或Write添加调试信息 3.按F5启动调试程序 4. ...

  4. Add File as a Link on Visual Studio

    https://stackoverflow.com/questions/18963750/add-file-as-a-link-on-visual-studio-debug-vs-publish Ev ...

  5. How to build mscorlib.dll with visual studio

    Recently, Microsoft Corportation has released a new look for .NET Reference Source. And you may find ...

  6. Visual Studio 中 Build 和 Rebuild 的区别

    因为之前写的程序比较小,编译起来比较快,所以一直都没有太在意 Build 和 Rebuild 之间的区别,后来发现两个还是有很大不同. Build 只针对在上次编译之后更改过的文件进行编译,在项目比较 ...

  7. Visual Studio Support (DDEX)

    原文 VS2012,VS2013,and VS2015Pro+NpgsqlDdexProvider+EFv6 how to(by @kenjiuno) Reference: #213 Overview ...

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

    SmartPaster - (FREE) Copy/Paste code generator for strings AnkhSvn - (FREE) SVN Source Control Integ ...

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

    摘至:http://blog.csdn.net/lp310018931/article/details/47991759 首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件 ...

随机推荐

  1. 解决win环境下访问本机虚拟机中centos7 ftp服务器的问题

    inux搭建ftp服务器 1.安装软件: yum install vsftpd 2.修改配置文件vsftpd.conf: vim /etc/vsftpd/vsftpd.conf 把anonymous_ ...

  2. MAC 的ideal 修改 项目名称

    在使用 ideal的时候 ,我拷贝了一个文件,想要修改项目的名称,改了qcs-regulation-hefei 但是 (1)我改了项目名称: (2)还改了 pom.xml 但是还是不行,来回切换不同的 ...

  3. sqlplus命令行登录oracle数据库的N种方法盘点

    欢迎访问我的个人博客IT废柴,本文永久链接移至:sqlplus命令行登录oracle数据库的N种方法盘点 sqlplus有几种登陆方式Oracle数据库, 比如: 1.以操作系统权限认证的oracle ...

  4. 使用ffmpeg将Mp4转gif

    视频转动图,是个强需求,家大业大的微博相册只可上传图片,进而基于微博相册的生态也是如此.目前,网络上有许多转换.压缩的网站,多数执行速度慢或者收费,体验较差. ffmpeg是一个开源的音频处理软件,支 ...

  5. Linux下MySql的登陆和管理操作

    一.mysql数据库启停1.linux下启动mysql的命令:    mysqladmin start/ect/init.d/mysql start (前面为mysql的安装路径)2.linux下重启 ...

  6. P1238 走迷宫

    原题链接 https://www.luogu.org/problemnew/show/P1238 为了巩固一下刚学习的广搜,练一下迷宫类型的题 不过这道题我用的深搜..... 看问题,我们就知道这道题 ...

  7. U68364 _GC滑迷宫

    题目背景 _GC买了一双蔡徐坤一代. 题目描述 _GC进入了一个n*m的迷宫.本题的特殊之处在于,_GC只能滑着走.具体来说就是,选定一个方向后,_GC会一直向该方向滑,直到撞到墙.会给出_GC的起始 ...

  8. Magento 2 自带模态的应用

    Modal widget in Magento 2 Magento 2 自带模态的应用 使用magento 2 的自带模态组件,以下代码只供参考使用. 1,DOM >模态块与触发元素 .pthm ...

  9. 用CNN对CIFAR10进行分类(pytorch)

    CIFAR10有60000个\(32*32\)大小的有颜色的图像,一共10种类别,每种类别有6000个. 训练集一共50000个图像,测试集一共10000个图像. 先载入数据集 import nump ...

  10. (八)控件介绍,QLable

    Radio单选框 默认互斥,加GroupBox进行分组可以解决这个 checkBox复选 ListWidget TableWIdget:有表头 #include "widget.h" ...