在大多数情况下,您只需将Visual Studio为您设置的任何内容作为默认值……我指的是在解决方案资源管理器中选择的每个文件的BuildAction属性。有很多选择,很难知道每一个会做什么。
当前回答
生成操作控制项目中每个项的MSBuild项类型。例如,MyClass.cs上的Compile构建操作在.csproj文件中是这样的:
<ItemGroup>
<Compile>MyClass.cs</Compile>
</ItemGroup>
根据约定,项目类型具有特定的含义。常见的类型有Compile、Content和None,但也有其他类型。
例如,.editorconfig文件有自己的项目类型(EditorConfigFiles)。文件可以通过标记为“c#分析器附加文件”(AdditionalFiles)来传递给分析器。
您还可以通过AvailableItemName在项目中为自己的目的定义自己的项类型。例如:
<ItemGroup>
<AvailableItemName Include="Foo" />
</ItemGroup>
这样做会产生:
其他回答
从文档中可以看到:
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.
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
Page -- Takes the specified XAML file, and compiles into BAML, and embeds that output into the managed resource stream for your assembly (specifically AssemblyName.g.resources), Additionally, if you have the appropriate attributes on the root XAML element in the file, it will create a blah.g.cs file, which will contain a partial class of the "codebehind" for that page; this basically involves a call to the BAML goop to re-hydrate the file into memory, and to set any of the member variables of your class to the now-created items (e.g. if you put x:Name="foo" on an item, you'll be able to do this.foo.Background = Purple; or similar.
ApplicationDefinition——类似于Page,只不过它更进一步,为你的应用程序定义入口点,该入口点将实例化你的应用程序对象,在它上调用run,然后实例化由StartupUri属性设置的类型,并将给出你的主窗口。
同时,需要明确的是,这个问题在它的结果集中是无限的;任何人都可以通过构建MSBuild任务来定义额外的BuildActions。如果您查看%systemroot%\Microsoft.net\framework\v{version}\目录,并查看Microsoft.Common.targets文件,您应该能够破译更多(例如,在VS Pro和以上版本中,有一个“Shadow”操作,允许您生成私有访问器来帮助单元测试私有类。
在VS2008中,最有用的文档条目是:
构建WPF应用程序(WPF)
ms-help: / / MS.VSCC.v90 / MS.MSDNQTR.v90.en / wpf_conceptual / html / a58696fd bdad - 4 b55 - 9759 - 136 - dfdf8b91c.htm
ApplicationDefinition 标识包含应用程序定义的XAML标记文件(根元素为application的XAML标记文件)。当Install为true且OutputType为winexe时,ApplicationDefinition是必选项。一个WPF应用程序以及MSBuild项目只能有一个ApplicationDefinition。
页面 标识一个XAML标记文件,该文件的内容被转换为二进制格式并编译为程序集。页面项通常与代码隐藏类一起实现。
最常见的Page项是XAML文件,其顶级元素是以下其中之一:
Window (System.Windows..::.Window).
Page (System.Windows.Controls..::.Page).
PageFunction (System.Windows.Navigation..::.PageFunction<(Of <(T>)>)).
ResourceDictionary (System.Windows..::.ResourceDictionary).
FlowDocument (System.Windows.Documents..::.FlowDocument).
UserControl (System.Windows.Controls..::.UserControl).
资源 标识编译为应用程序程序集的资源文件。如前所述,UICulture处理资源项。
内容 标识随应用程序分发的内容文件。描述内容文件的元数据被编译到应用程序中(使用AssemblyAssociatedContentFileAttribute)。
VS2010有一个属性用于“构建动作”,还有一个属性用于“复制到输出目录”。因此,如果复制属性设置为“更新时复制”或“始终复制”,'None'的操作仍然会复制到构建目录。
因此,“内容”的构建动作应该保留,以指示您将通过“应用程序”访问的内容。GetContentStream”
对于一些外部链接的.config include,我使用了“None”的“构建动作”设置和“如果更新则复制到输出目录”的“复制到输出目录”设置。
G.
推荐文章
- Visual Studio代码如何解决合并冲突与git?
- _references.js是用来做什么的?
- 如何为新的c#类/接口编辑Visual Studio模板?
- IIS Express Windows身份验证
- 配置系统初始化失败
- 在Visual Studio中是否有标准的快捷键来构建当前项目?
- 我如何让我的解决方案在Visual Studio回到在线的TFS?
- 如何在Visual Studio中生成getter和setter ?
- Visual Studio后构建事件-复制到相对目录位置
- 指定的参数超出有效值范围。参数名称:site
- 如何使用MS Visual Studio进行Android开发?
- 在安装了Resharper的Visual Studio中,键盘快捷键不活跃
- 在Visual Studio中如何在项目/解决方案之间共享代码?
- 用于自动添加“using”语句的Visual Studio键盘快捷方式
- Resharper Alt Enter不工作