在大多数情况下,您只需将Visual Studio为您设置的任何内容作为默认值……我指的是在解决方案资源管理器中选择的每个文件的BuildAction属性。有很多选择,很难知道每一个会做什么。


当前回答

从文档中可以看到:

The BuildAction property indicates what Visual Studio does with a file when a build is executed. BuildAction 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.

其他回答

生成操作控制项目中每个项的MSBuild项类型。例如,MyClass.cs上的Compile构建操作在.csproj文件中是这样的:

<ItemGroup>
  <Compile>MyClass.cs</Compile>
</ItemGroup>

根据约定,项目类型具有特定的含义。常见的类型有Compile、Content和None,但也有其他类型。

例如,.editorconfig文件有自己的项目类型(EditorConfigFiles)。文件可以通过标记为“c#分析器附加文件”(AdditionalFiles)来传递给分析器。

您还可以通过AvailableItemName在项目中为自己的目的定义自己的项类型。例如:

<ItemGroup>
  <AvailableItemName Include="Foo" />
</ItemGroup>

这样做会产生:

Microsoft Connect的这一页(解释DesignData和DesignDataWithDesignTimeCreatableTypes)类型如何?引用:

下面描述了样本数据文件的两个构建操作。

样例数据.xaml文件必须分配以下构建操作之一:

DesignData:样例数据类型将被创建为伪类型。当样例数据类型不可创建或具有您希望为其定义样例数据值的只读属性时,请使用此构建操作。

DesignDataWithDesignTimeCreatableTypes:使用样例数据文件中定义的类型创建样例数据类型。当可以使用样例数据类型的默认空构造函数创建样例数据类型时,使用此构建操作。

不是很详尽,但至少给了一个提示。这个MSDN演练也提供了一些想法。我不知道这些构建操作是否也适用于非silverlight项目。

从文档中可以看到:

The BuildAction property indicates what Visual Studio does with a file when a build is executed. BuildAction 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.

Fakes: Microsoft Fakes(单元测试隔离)框架的一部分。在所有Visual Studio版本上不可用。Fakes用于支持项目中的单元测试,通过用stub或shims替换应用程序的其他部分来帮助您隔离正在测试的代码。更多信息请点击:https://msdn.microsoft.com/en-us/library/hh549175.aspx

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: Allows you to retrieve a file (in the same directory as the assembly) as a stream via Application.GetContentStream(URI). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which Visual Studio graciously adds when you mark a file as "Content" Embedded resource: Embeds the file in an exclusive assembly manifest resource. 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. 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) 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" SplashScreen (WPF only): An image that is marked as SplashScreen is shown automatically when an WPF application loads, and then fades DesignData: Compiles XAML viewmodels so that usercontrols can be previewed with sample data in Visual Studio (uses mock types) 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 CodeAnalysisDictionary: An XML file containing custom word dictionary for spelling rules