常用的 MSBuild 项目项Common MSBuild project items

在 MSBuild 中,项是对一个或多个文件的命名引用。In MSBuild, an item is a named reference to one or more files. 项包含元数据(如文件名、路径和版本号)。Items contain metadata such as file names, paths, and version numbers. Visual Studio 中的所有项目类型具有几个通用项。All project types in Visual 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.
“属性”Name 可选的字符串。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. 此项仅适用于 .NET 项目。This item applies only to .NET projects.

项元数据名称Item metadata name 描述Description
“属性”Name 可选的字符串。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

表示传递到 ResolveComReference 目标的 TypeLibFiles 参数的类型库的列表。Represents a list of type libraries that are passed to the TypeLibFiles parameter of the ResolveComReference target. 此项仅适用于 .NET 项目。This item applies only to .NET projects.

项元数据名称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
“属性”Name 必选字符串。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. ProjectReference 项由 ResolveProjectReferences 目标转换为 Reference 项,因此,如果转换过程没有将其覆盖,则 Reference 上的任何有效元数据都可能在 ProjectReference 上有效。ProjectReference items are transformed into Reference items by the ResolveProjectReferences target, so any valid metadata on a Reference may be valid on ProjectReference, if the transformation process doesn't overwrite it.

项元数据名称Item metadata name 描述Description
“属性”Name 可选的字符串。Optional string. 引用的显示名称。The display name of the reference.
GlobalPropertiesToRemoveGlobalPropertiesToRemove 可选的 string[]Optional string[]. 在生成引用项目时要删除的属性的名称,例如 RuntimeIdentifier;PackOnBuildNames of properties to remove when building the referenced project, for example RuntimeIdentifier;PackOnBuild. 默认为空。Defaults to empty.
项目Project 可选的字符串。Optional string. 引用的 GUID,形式为 {12345678-1234-1234-1234-1234567891234}。A GUID for the reference, in the form {12345678-1234-1234-1234-1234567891234}.
OutputItemTypeOutputItemType 可选的字符串。Optional string. 要将目标输出发到的项类型。Item type to emit target outputs into. 默认为空。Default is blank. 如果“引用元数据”设置为“true”(默认),那么目标输出将成为编译器的引用。If the Reference metadata is set to "true" (default) then target outputs will become references for the compiler.
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.
SetConfigurationSetConfiguration 可选的字符串。Optional string. 为引用的项目设置全局属性 Configuration,例如 Configuration=ReleaseSets the global property Configuration for the referenced project, for example Configuration=Release.
SetPlatformSetPlatform 可选的字符串。Optional string. 为引用的项目设置全局属性 Platform,例如 Platform=AnyCPUSets the global property Platform for the referenced project, for example Platform=AnyCPU.
SetTargetFrameworkSetTargetFramework 可选的字符串。Optional string. 为引用的项目设置全局属性 TargetFramework,例如 TargetFramework=netstandard2.0Sets the global property TargetFramework for the referenced project, for example TargetFramework=netstandard2.0.
SkipGetTargetFrameworkPropertiesSkipGetTargetFrameworkProperties 可选的布尔值。Optional boolean. 如果为 true,则在不协商最兼容的 TargetFramework 值的情况下生成引用的项目。If true, builds the referenced project without negotiating the most compatible TargetFramework value. 默认为 falseDefaults to false.
目标Targets 可选的 string[]Optional string[]. 应生成的引用项目中的目标的列表,以分号分隔。Semicolon separated list of targets in the referenced projects that should be built. 默认值为 $(ProjectReferenceBuildTargets) 的值,该值默认为空,指示默认目标。Default is the value of $(ProjectReferenceBuildTargets) which defaults to empty, indicating the default targets.

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 Studio 集成开发环境 (IDE) 为项目生成了文件。Indicates whether the file was generated for the project by the Visual 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 Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual 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 Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual 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 Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual 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 Studio 中的“解决方案资源管理器”中显示文件。Indicates whether to display the file in Solution Explorer in Visual 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

AssemblyMetadataAssemblyMetadata

表示要生成为 [AssemblyMetadata(key, value)] 的程序集特性。Represents assembly attributes to be generated as [AssemblyMetadata(key, value)].

项元数据名称Item metadata name 描述Description
包括Include 成为 AssemblyMetadataAttribute 特性构造函数中的第一个参数(键)。Becomes the first parameter (the key) in the AssemblyMetadataAttribute attribute constructor.
“值”Value 必选字符串。Required string. 成为 AssemblyMetadataAttribute 特性构造函数中的第二个参数(值)。Becomes the second parameter (the value) in the AssemblyMetadataAttribute attribute constructor.

备注

此项适用于使用 SDK for .NET 5(和 .NET Core)及更高版本的项目。This item applies to projects using the SDK for .NET 5 (and .NET Core) and later versions.

InternalsVisibleToInternalsVisibleTo

指定要作为 [InternalsVisibleTo(..)] 程序集特性发出的程序集。Specifies assemblies to be emitted as [InternalsVisibleTo(..)] assembly attributes.

项元数据名称Item metadata name 描述Description
包括Include 程序集名称。The assembly name.
KeyKey 可选的字符串。Optional string. 程序集的公钥。The public key of the assembly.

备注

此项适用于使用 SDK for .NET 5(和 .NET Core)及更高版本的项目。This item applies to projects using the SDK for .NET 5 (and .NET Core) and later versions.

BaseApplicationManifestBaseApplicationManifest

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

CodeAnalysisImportCodeAnalysisImport

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

导入Import

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

请参阅See also