常用的 MSBuild 项目项Common MSBuild project items

MSBuildMSBuild 中,项是对一个或多个文件的命名引用。In MSBuildMSBuild, an item is a named reference to one or more files. 项包含元数据(如文件名、路径和版本号)。Items contain metadata such as file names, paths, and version numbers. Visual StudioVisual Studio 中的所有项目类型具有几个通用项。All project types in Visual StudioVisual Studio have several items in common. 在文件 Microsoft.Build.CommonTypes.xsd 中定义了这些项。These items are defined in the file Microsoft.Build.CommonTypes.xsd.

常用项Common items

以下是所有通用项目项的列表。The following is a list of all the common project items.

参考Reference

表示项目中的程序集(托管)引用。Represents an assembly (managed) reference in the project.

项元数据名称Item metadata name 说明Description
HintPathHintPath 可选的字符串。Optional string. 程序集的相对或绝对路径。Relative or absolute path of the assembly.
nameName 可选的字符串。Optional string. 程序集的显示名称,例如“System.Windows.Forms”。The display name of the assembly, for example, "System.Windows.Forms."
FusionNameFusionName 可选的字符串。Optional string. 指定项的简单或强合成名称。Specifies the simple or strong fusion name for the item.

此特性存在时,可以节省时间,因为程序集文件不必打开即可获取合成名称。When this attribute is present, it can save time because the assembly file does not have to be opened to obtain the fusion name.
SpecificVersionSpecificVersion 可选的布尔值。Optional boolean. 指定是否应仅引用合成名称中的版本。Specifies whether only the version in the fusion name should be referenced.
别名Aliases 可选的字符串。Optional string. 引用的任何别名。Any aliases for the reference.
PrivatePrivate 可选的布尔值。Optional boolean. 指定是否应将引用复制到输出文件夹。Specifies whether the reference should be copied to the output folder. 此特性与 Visual Studio IDE 中的引用的“复制本地”属性相匹配。This attribute matches the Copy Local property of the reference that's in the Visual Studio IDE.

COMReferenceCOMReference

表示项目中的 COM(非托管)组件引用。Represents a COM (unmanaged) component reference in the project.

项元数据名称Item metadata name 说明Description
nameName 可选的字符串。Optional string. 组件的显示名称。The display name of the component.
GUIDGuid 必选字符串。Required string. 组件的 GUID,形式为 {12345678-1234-1234-1234-1234567891234}。A GUID for the component, in the form {12345678-1234-1234-1234-1234567891234}.
VersionMajorVersionMajor 必选字符串。Required string. 组件版本号的主要部分。The major part of the version number of the component. 例如,如果完整版本号是“5.46”,则显示“5”。For example, "5" if the full version number is "5.46."
VersionMinorVersionMinor 必选字符串。Required string. 组件版本号的次要部分。The minor part of the version number of the component. 例如,如果完整版本号是“5.46”,则显示“46”。For example, "46" if the full version number is "5.46."
LCIDLCID 可选的字符串。Optional string. 组件的 LocaleID。The LocaleID for the component.
WrapperToolWrapperTool 可选的字符串。Optional string. 对组件使用的包装工具的名称,例如“tlbimp”。The name of the wrapper tool that is used on the component, for example, "tlbimp."
IsolatedIsolated 可选的布尔值。Optional boolean. 指定组件是否为免注册组件。Specifies whether the component is a reg-free component.

COMFileReferenceCOMFileReference

表示馈送到 ResolvedComreference 目标中的类型库的列表。Represents a list of type libraries that feed into the ResolvedComreference target.

项元数据名称Item metadata name 说明Description
WrapperToolWrapperTool 可选的字符串。Optional string. 对组件使用的包装工具的名称,例如“tlbimp”。The name of the wrapper tool that is used on the component, for example, "tlbimp."

NativeReferenceNativeReference

表示本机清单文件或对此类文件的引用。Represents a native manifest file or a reference to such a file.

项元数据名称Item metadata name 说明Description
nameName 必选字符串。Required string. 清单文件基名称。The base name of the manifest file.
HintPathHintPath 必选字符串。Required string. 清单文件的相对路径。The relative path of the manifest file.

ProjectReferenceProjectReference

表示对另一个项目的引用。Represents a reference to another project.

项元数据名称Item metadata name 说明Description
nameName 可选的字符串。Optional string. 引用的显示名称。The display name of the reference.
项目Project 可选的字符串。Optional string. 引用的 GUID,形式为 {12345678-1234-1234-1234-1234567891234}。A GUID for the reference, in the form {12345678-1234-1234-1234-1234567891234}.
PackagePackage 可选的字符串。Optional string. 所引用的项目文件的路径。The path of the project file that is being referenced.
ReferenceOutputAssemblyReferenceOutputAssembly 可选的布尔值。Optional boolean. 如果设置为 false,则不包括引用项目的输出作为此项目的引用,但仍可确保在此项目之前生成其他项目。If set to false, does not include the output of the referenced project as a Reference of this project, but still ensures that the other project builds before this one. 默认为 trueDefaults to true.

CompileCompile

表示编译器的源文件。Represents the source files for the compiler.

项元数据名称Item metadata name 说明Description
DependentUponDependentUpon 可选的字符串。Optional string. 指定该文件正确编译所依赖的文件。Specifies the file this file depends on to compile correctly.
AutoGenAutoGen 可选的布尔值。Optional boolean. 指示是否已由 Visual StudioVisual Studio 集成开发环境 (IDE) 为项目生成了文件。Indicates whether the file was generated for the project by the Visual StudioVisual Studio integrated development environment (IDE).
链接Link 可选的字符串。Optional string. 文件在物理上处于项目文件的影响范围之外时要显示的符号路径。The notational path to be displayed when the file is physically located outside the influence of the project file.
可见Visible 可选的布尔值。Optional boolean. 指示是否要在 Visual StudioVisual Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual StudioVisual Studio.
CopyToOutputDirectoryCopyToOutputDirectory 可选的字符串。Optional string. 确定是否将文件复制到输出目录。Determines whether to copy the file to the output directory. 值为:Values are:

1.Never1. Never
2.Always2. Always
3.PreserveNewest3. PreserveNewest

EmbeddedResourceEmbeddedResource

表示要在生成的程序集中嵌入的资源。Represents resources to be embedded in the generated assembly.

项元数据名称Item metadata name 说明Description
DependentUponDependentUpon 可选的字符串。Optional string. 指定该文件正确编译所依赖的文件Specifies the file this file depends on to compile correctly
GeneratorGenerator 必选字符串。Required string. 在此项上运行的任何文件生成器的名称。The name of any file generator that is run on this item.
LastGenOutputLastGenOutput 必选字符串。Required string. 在此项上运行的任何文件生成器创建的文件的名称。The name of the file that was created by any file generator that ran on this item.
CustomToolNamespaceCustomToolNamespace 必选字符串。Required string. 在此项上运行的任何文件生成器应在其中创建代码的命名空间。The namespace in which any file generator that runs on this item should create code.
链接Link 可选的字符串。Optional string. 如果文件在物理上处于项目的影响范围之外,则显示符号路径。The notational path is displayed if the file is physically located outside the influence of the project.
可见Visible 可选的布尔值。Optional boolean. 指示是否要在 Visual StudioVisual Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual StudioVisual Studio.
CopyToOutputDirectoryCopyToOutputDirectory 可选的字符串。Optional string. 确定是否将文件复制到输出目录。Determines whether to copy the file to the output directory. 值为:Values are:

1.Never1. Never
2.Always2. Always
3.PreserveNewest3. PreserveNewest
LogicalNameLogicalName 必选字符串。Required string. 嵌入资源的逻辑名称。The logical name of the embedded resource.

内容Content

表示不会编译到项目中,但可能会嵌入到其中或随其一起发布的文件。Represents files that are not compiled into the project, but may be embedded or published together with it.

项元数据名称Item metadata name 说明Description
DependentUponDependentUpon 可选的字符串。Optional string. 指定该文件正确编译所依赖的文件。Specifies the file this file depends on to compile correctly.
GeneratorGenerator 必选字符串。Required string. 在此项上运行的任何文件生成器的名称。The name of any file generator that runs on this item.
LastGenOutputLastGenOutput 必选字符串。Required string. 在此项上运行的任何文件生成器创建的文件的名称。The name of the file that was created by any file generator that was run on this item.
CustomToolNamespaceCustomToolNamespace 必选字符串。Required string. 在此项上运行的任何文件生成器应在其中创建代码的命名空间。The namespace in which any file generator that runs on this item should create code.
链接Link 可选的字符串。Optional string. 文件在物理上处于项目的影响范围之外时要显示的符号路径。The notational path to be displayed if the file is physically located outside the influence of the project.
PublishStatePublishState 必选字符串。Required string. 内容的发布状态,为以下任一项:The publish state of the content, either:

- 默认- Default
- 已包括- Included
- 已排除- Excluded
- 数据文件- DataFile
- 必备组件- Prerequisite
IsAssemblyIsAssembly 可选的布尔值。Optional boolean. 指定文件是否为程序集。Specifies whether the file is an assembly.
可见Visible 可选的布尔值。Optional boolean. 指示是否要在 Visual StudioVisual Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual StudioVisual Studio.
CopyToOutputDirectoryCopyToOutputDirectory 可选的字符串。Optional string. 确定是否将文件复制到输出目录。Determines whether to copy the file to the output directory. 值为:Values are:

1.Never1. Never
2.Always2. Always
3.PreserveNewest3. PreserveNewest

NoneNone

表示不应在生成过程中具有角色的文件。Represents files that should have no role in the build process.

项元数据名称Item metadata name 说明Description
DependentUponDependentUpon 可选的字符串。Optional string. 指定该文件正确编译所依赖的文件。Specifies the file this file depends on to compile correctly.
GeneratorGenerator 必选字符串。Required string. 在此项上运行的任何文件生成器的名称。The name of any file generator that is run on this item.
LastGenOutputLastGenOutput 必选字符串。Required string. 在此项上运行的任何文件生成器创建的文件的名称。The name of the file that was created by any file generator that ran on this item.
CustomToolNamespaceCustomToolNamespace 必选字符串。Required string. 在此项上运行的任何文件生成器应在其中创建代码的命名空间。The namespace in which any file generator that runs on this item should create code.
链接Link 可选的字符串。Optional string. 文件在物理上处于项目的影响范围之外时要显示的符号路径。The notational path to be displayed if the file is physically located outside the influence of the project.
可见Visible 可选的布尔值。Optional boolean. 指示是否要在 Visual StudioVisual Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual StudioVisual Studio.
CopyToOutputDirectoryCopyToOutputDirectory 可选的字符串。Optional string. 确定是否将文件复制到输出目录。Determines whether to copy the file to the output directory. 值为:Values are:

1.Never1. Never
2.Always2. Always
3.PreserveNewest3. PreserveNewest

BaseApplicationManifestBaseApplicationManifest

表示用于生成的基本应用程序清单,包含 ClickOnceClickOnce 部署安全信息。Represents the base application manifest for the build, and contains ClickOnceClickOnce deployment security information.

CodeAnalysisImportCodeAnalysisImport

表示要导入的 FxCop 项目。Represents the FxCop project to import.

导入Import

表示应由 Visual BasicVisual Basic 编译器导入其命名空间的程序集。Represents assemblies whose namespaces should be imported by the Visual BasicVisual Basic compiler.

请参阅See also