在创作项目文件时,可能需要使用保留的 XML 字符,例如在属性值或任务参数值中。 但是,某些保留字符必须替换为命名实体,以便可以分析项目文件。
使用保留字符
下表介绍必须替换为相应命名实体的保留的 XML 字符,以便可以分析项目文件。
保留字符 | 命名实体 |
---|---|
< | < |
> | > |
& | & |
" | " |
“ | ' |
在项目文件中使用双引号
将双引号替换为相应的字符实体 "。 例如,若要在
EXEFile
项列表两边放置双引号,请键入:<Message Text="The output file is "@(EXEFile)"."/>
示例
在以下代码示例中,双引号用于在由项目文件输出的消息中突出显示文件名。
<Project DefaultTargets="Compile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
<!-- Set the application name as a property -->
<PropertyGroup>
<appname>"HelloWorldCS"</appname>
</PropertyGroup>
<!-- Specify the inputs -->
<ItemGroup>
<CSFile Include = "consolehwcs1.cs" />
</ItemGroup>
<Target Name = "Compile">
<!-- Run the Visual C# compilation using input
files of type CSFile -->
<Csc Sources = "@(CSFile)">
<!-- Set the OutputAssembly attribute of the CSC task
to the name of the executable file that is created -->
<Output
TaskParameter = "OutputAssembly"
ItemName = "EXEFile"/>
</Csc>
<!-- Log the file name of the output file -->
<Message Text="The output file is "@(EXEFile)"."/>
</Target>
</Project>