Use Reserved XML Characters in Project Files
When you author project files, you might need to use reserved XML characters, for example, in property values or in task parameter values. However, some reserved characters must be replaced by a named entity so that the project file can be parsed.
In this example, double quotes are used to highlight the file name in the message that is output by the "Hello World" project file.
Reserved Characters
The following reserved characters must be replaced by the corresponding named entity so that the project file can be parsed:
Reserved Character Named Entity
< (less than) <
> (greater than) >
& (ampersand) &
" (double quote) "
' (apostrophe) '
" ExampleIf you want to use double quotes to highlight a file name in a message such as
The output file is "@(EXEFile)"
replace the double quotes with " in the project file, as shown in the following example:
<Message Text="The output file is "@(EXEFile)"."/>
< ExampleIf you are writing an Exec task that redirects input using the less than symbol, such as
findstr "image" < data.txt
replace the less than symbol with < in the project file:
<Task Name="Exec"
Command="findstr "image" < data.txt"/>
Building a Project
To build the Visual C# or Visual Basic "Hello World" project from the command line, navigate to the directory that contains the project file and type:
msbuild consolehwcs1.proj
or
msbuild consolehwvb1.proj
Project Files
Download Code - C#Download Code - VB Visual C# example
<Project
DefaultTargets="Compile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <!-- Set the application name as a property -->
<appname>HelloWorldCS</appname> </PropertyGroup> <ItemGroup> <!-- Specify the inputs by type and file name -->
<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)&quot;."/>
</Target>
</Project>
Visual Basic example
<Project
DefaultTargets="Compile"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <!-- Set the application name as a property -->
<appname>HelloWorldVB</appname> </PropertyGroup> <ItemGroup> <!-- Specify the inputs by type and file name -->
<VBFile Include="consolehwvb1.vb" />
</ItemGroup> <Target Name="Compile">
<!-- Run the Visual Basic compilation using input files of type
VBFile -->
<Vbc Sources="@(VBFile)">
<!-- Set the
OutputAssembly output value to the
EXEFile property -->
<Output
TaskParameter="OutputAssembly"
ItemName="EXEFile" />
</Vbc>
<!-- Log the file name of the output file -->
<Message Text="The output file is "@(EXEFile)""/>
</Target>
</Project>