Export (0) Print
Expand All

How to: Set Policy Programmatically in a Visual Studio Templates and Policy Wizard 

Visual Studio 2005

When creating a Visual Studio Templates and Policy Wizard, you might want to set the policy file for the resulting application programmatically, rather than requiring the application developers to apply it. The policy file for a project or Solution Folder can be set by setting the VSPolicyExtenderProvider.TDLFileNAME property. The following procedure describes how to set the policy file for a project or Solution Folder that is being created by a wizard.

Setting the Policy File Programmatically

To assign a policy file to a project

  1. In your wizard code, create a project or solution folder. For more information, see Walkthrough: Creating a Wizard.

  2. Add a method similar to the following example to your wizard.

    Sub SetPolicyFile(ByVal project As EnvDTE.Project, ByVal policyFile As String)
        Dim props as EnvDTE.Properties
        props = project.Properties
        props.Item("VSPolicyExtenderProvider.TDLFileNAME").Value = _
           policyFile
    End Sub
    

    void SetPolicyFile(EnvDTE.Project project, string policyFile)
    {
        EnvDTE.Properties props;
        props = project.Properties;
        props.Item("VSPolicyExtenderProvider.TDLFileNAME").Value = policyFile;
    }
    

    In this example, the policyFile variable is a string representing the path to the appropriate .vspolicy file. The project variable is a variable of the EnvDTE.Project policy that references a project or Solution Folder that is being created by your wizard. This example assumes a reference to the EnvDTE namespace. Calling this method sets the policy file to the supplied value.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft