AppliesTo Element (Visual Studio Templates)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at AppliesTo Element (Visual Studio Templates).

Specifies an optional expression to match one or more capabilities. (see VsProjectCapabilityExpressionMatcher). Capabilities are exposed by project types via the hierarchy as a property VSHPROPID_ProjectCapabilities. In this way, the template can be shared by multiple project types that have common applicable capabilities.

This element is optional. There can be a maximum of one instance in a template file. This element only enables an item template to opt-in as applicable, based on the capabilities of the currently selected active project. It cannot be used to make an item template not applicable. If AppliesTo is absent or the expression does not successfully opt in, then TemplateID or TemplateGroupID is used to make the template applicable, as with previous versions of the product.

Introduced in Visual Studio 2013 Update 2. To reference the correct version, see Referencing Assemblies Delivered in the Visual Studio 2013 SDK Update 2.

<VSTemplate>
<TemplateData>
<AppliesTo>

<AppliesTo>Capability1</AppliesTo>   

The following sections describe attributes, child elements, and parent elements.

Attributes

None.

Child Elements

None.

Parent Elements

ElementDescription
TemplateDataCategorizes the template.

A text value is required. This text specifies the capabilities of the project.

Valid expression syntax is defined as:

  • The capability expression, such as "(VisualC | CSharp) + (MSTest | NUnit)".

  • The "|" is the OR operator.

  • The "&" and "+" characters are both AND operators.

  • The "!" character is the NOT operator.

  • Parentheses force evaluation-precedence order.

  • A null or empty expression is evaluated as a match.

  • Project capabilities may be any character except these reserved characters: "'`:;,+-*/\!~|&%$@^()={}[]<>? \t\b\n\r

The following example shows three different templates. Template1 applies either to all C# project types or any other project type that supports the WindowsAppContainer capability. Template2 applies to all C# projects of any kind. Template3 applies to C# projects that are not WindowsAppContainer projects.

<!--  Template 1 -->  
<?xml version="1.0" encoding="utf-8"?>  
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/developer/vstemplate/2005">  
    <TemplateData>  
        <AppliesTo>CSharp | WindowsAppContainer</AppliesTo>   
    </TemplateData>  
</VSTemplate>  
  
<!--  Template 2 -->  
<?xml version="1.0" encoding="utf-8"?>  
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/developer/vstemplate/2005">  
    <TemplateData>  
        <AppliesTo>CSharp</AppliesTo>   
    </TemplateData>  
</VSTemplate>  
  
<!--  Template 1 -->  
<?xml version="1.0" encoding="utf-8"?>  
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/developer/vstemplate/2005">  
    <TemplateData>  
        <AppliesTo>CSharp_Class + (!WindowsAppContainer)</AppliesTo>   
    </TemplateData>  
</VSTemplate>  
  

Visual Studio Template Schema Reference
Creating Project and Item Templates

Show: