<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:msb="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <!-- ======================================================================================= -->
    <xs:element name="Project">
        <xs:complexType>
            <xs:sequence>
                <xs:group ref="msb:ProjectLevelTagExceptTargetOrImportType" minOccurs="0" maxOccurs="unbounded"/>
                <!-- must be at least one Target or Import tag-->
                <xs:group ref="msb:TargetOrImportType"/>
                <xs:group ref="msb:ProjectLevelTagType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="DefaultTargets" type="xs:string" use="optional">
                <xs:annotation>
                    <xs:documentation>Optional semi-colon separated list of one or more targets that will be built if no targets are otherwise specified</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <!-- ======================================================================================= -->
    <xs:group name="ProjectLevelTagExceptTargetOrImportType">
        <xs:choice>
            <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
            <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
            <xs:element name="Choose" type="msb:ChooseType"/>
            <xs:element name="Error" type="msb:WarningErrorOutsideTargetType">
                <xs:annotation>
                    <xs:documentation>Logs an Error event</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Warning" type="msb:WarningErrorOutsideTargetType">
                <xs:annotation>
                    <xs:documentation>Logs a Warning event</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Message" type="msb:MessageOutsideTargetType"/>
            <xs:element name="UsingTask" type="msb:UsingTaskType"/>
            <xs:element name="ProjectExtensions" type="msb:ProjectExtensionsType"/>
        </xs:choice>
    </xs:group>
    <!-- ======================================================================================= -->
    <xs:group name="ProjectLevelTagType">
        <xs:choice>
            <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
            <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
            <xs:element name="Choose" type="msb:ChooseType"/>
            <xs:element name="Error" type="msb:WarningErrorOutsideTargetType">
                <xs:annotation>
                    <xs:documentation>Logs an Error event</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Warning" type="msb:WarningErrorOutsideTargetType">
                <xs:annotation>
                    <xs:documentation>Logs a Warning event</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Message" type="msb:MessageOutsideTargetType"/>
            <xs:element name="UsingTask" type="msb:UsingTaskType"/>
            <xs:element name="Target" type="msb:TargetType"/>
            <xs:element name="Import" type="msb:ImportType"/>
            <xs:element name="ProjectExtensions" type="msb:ProjectExtensionsType"/>
        </xs:choice>
    </xs:group>
    <!-- ======================================================================================= -->
    <xs:group name="TargetOrImportType">
        <xs:choice>
            <xs:element name="Target" type="msb:TargetType"/>
            <xs:element name="Import" type="msb:ImportType"/>
        </xs:choice>
    </xs:group>
    <!-- ======================================================================================= -->
    <xs:complexType name="TargetType">
        <xs:annotation>
            <xs:documentation>Groups tasks into a section of the build process</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="msb:Task"/>
            </xs:choice>
            <xs:element name="OnError" type="msb:OnErrorType" minOccurs="0" maxOccurs="unbounded"/>
            <!-- no elements are allowed under Target after an OnError element-->
        </xs:sequence>
        <xs:attribute name="Name" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation>Name of the target</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="DependsOnTargets" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional semi-colon separated list of targets that should be run before this target</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Inputs" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional semi-colon separated list of files that form inputs into this target. Their timestamps will be compared with the timestamps of files in Outputs to determine whether the Target is up to date</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Outputs" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional semi-colon separated list of files that form outputs into this target. Their timestamps will be compared with the timestamps of files in Inputs to determine whether the Target is up to date</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the Target and the targets it depends on should be run</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="PropertyGroupType">
        <xs:annotation>
            <xs:documentation>Groups property definitions</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="msb:Property"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the PropertyGroup should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="ItemGroupType">
        <xs:annotation>
            <xs:documentation>Groups item list definitions</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="msb:Item"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the ItemGroup should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="ChooseType">
        <xs:annotation>
            <xs:documentation>Groups When and Otherwise elements</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="When" type="msb:WhenType" maxOccurs="unbounded"/>
            <xs:element name="Otherwise" type="msb:OtherwiseType" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="WhenType">
        <xs:annotation>
            <xs:documentation>Groups PropertyGroup and/or ItemGroup elements</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
                <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
                <xs:element name="Choose" type="msb:ChooseType"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the child PropertyGroups and/or ItemGroups should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="OtherwiseType">
        <xs:annotation>
            <xs:documentation>Groups PropertyGroup and/or ItemGroup elements that are used if no Conditions on sibling When elements evaluate to true</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
                <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
                <xs:element name="Choose" type="msb:ChooseType"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="OnErrorType">
        <xs:annotation>
            <xs:documentation>Specifies targets to execute in the event of a recoverable error</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the targets should be executed</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="ExecuteTargets" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation>Semi-colon separated list of targets to execute</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="MessageOutsideTargetType">
        <xs:annotation>
            <xs:documentation>Logs an informational Message event, with an optional Importance</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the Message should be logged</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Importance" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional priority level. Allowed values are Low, Normal (default), and High</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Text" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Text to log</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="WarningErrorOutsideTargetType">
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the text should be logged</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Text" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Text to log</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="UsingTaskType">
        <xs:annotation>
            <xs:documentation>Declares where to load a task that will be used in the project</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the declaration should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="AssemblyName" type="msb:non_empty_string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional name of assembly containing the task. Either AssemblyName or AssemblyFile must be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="AssemblyFile" type="msb:non_empty_string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional path to assembly containing the task. Either AssemblyName or AssemblyFile must be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="TaskName" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation>Name of task class in the assembly</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="ImportType">
        <xs:annotation>
            <xs:documentation>Declares that the contents of another project file should be inserted at this location</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the import should occur</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Project" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation>Project file to import</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="ProjectExtensionsType" mixed="true">
        <xs:annotation>
            <xs:documentation>Optional section used by MSBuild hosts, that may contain arbitrary XML content that is ignored by MSBuild itself</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:any processContents="skip"/>
        </xs:sequence>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:element name="Item" type="msb:SimpleItemType" abstract="true"/>
    <!-- ======================================================================================= -->
    <!-- convenience type for items that have no meta-data-->
    <xs:complexType name="SimpleItemType">
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the items should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Include" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Semi-colon separated list of files (wildcards are allowed) or other item names to include in this item list</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Exclude" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Semi-colon separated list of files (wildcards are allowed) or other item names to exclude from the Include list</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <!-- general utility type allowing an item type to be defined but not its child meta-data-->
    <xs:complexType name="GenericItemType">
        <xs:complexContent>
            <xs:extension base="msb:SimpleItemType">
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:any namespace="##any" processContents="skip"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <!-- no type declared on this abstract element, so either a simple or complex type can be substituted for it.-->
    <xs:element name="Property" abstract="true"/>
    <!-- ======================================================================================= -->
    <!-- convenience type for properties that just want to allow text and no elements in them-->
    <xs:complexType name="StringPropertyType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="Condition" type="xs:string" use="optional">
                    <xs:annotation>
                        <xs:documentation>Optional expression evaluated to determine whether the property should be evaluated</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <!-- general utility type allowing text and/or elements inside-->
    <xs:complexType name="GenericPropertyType" mixed="true">
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:any namespace="##any" processContents="skip"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the property should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:element name="Task" type="msb:TaskType" abstract="true"/>
    <!-- ======================================================================================= -->
    <xs:complexType name="TaskType">
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Output">
                <xs:annotation>
                    <xs:documentation>Optional element specifying a specific task output to be gathered</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:attribute name="TaskParameter" type="msb:non_empty_string" use="required">
                        <xs:annotation>
                            <xs:documentation>Task parameter to gather. Matches the name of a .NET Property on the task class that has an [Output] attribute</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="ItemName" type="msb:non_empty_string" use="optional">
                        <xs:annotation>
                            <xs:documentation>Optional name of an item list to put the gathered outputs into. Either ItemName or PropertyName must be specified</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="PropertyName" type="msb:non_empty_string" use="optional">
                        <xs:annotation>
                            <xs:documentation>Optional name of a property to put the gathered output into. Either PropertyName or ItemName must be specified</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="Condition" type="xs:string" use="optional">
                        <xs:annotation>
                            <xs:documentation>Optional expression evaluated to determine whether the output should be gathered</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional expression evaluated to determine whether the task should be executed</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="ContinueOnError" type="msb:non_empty_string" use="optional">
            <xs:annotation>
                <xs:documentation>Optional boolean indicating whether a recoverable task error should be ignored. Default false</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <!-- We don't need the anyAttribute here because other types deriving from this type will add the right attributes.-->
    </xs:complexType>
    <!-- ======================================================================================= -->
    <!-- XSD considers an empty-valued attribute to satisfy use="required", but we want it to have a non-empty value in most cases, hence this utility type. -->
    <xs:simpleType name="non_empty_string">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
