Search code examples
c#visual-studiotemplatesvisual-studio-templates

Destination Directory parameter in Item Template - Visual Studio


I have created a C# Item template and have included several template parameters. I would like to have the path of the newly created .cs file (using Add, New Item..) included in the file.

When creating C# Project templates, you can use this parameter in the template file:

$destinationdirectory$

Which will produce the path to the directory of the .csproj once created, something like:

C:\Users\username\source\repos\solutionfolder\projectfolder

When using the same parameter in an item template, the parameter isn't replaced (all other parameters are), the newly created .cs still contains:

$destinationdirectory$

What parameter can I use to get the path of the newly created .cs file? Failing that, the path to the solution the new item was created?

This MSDN Page is the only reference of parameters for project/item templates I have found. It only includes about 15 parameters, which falls very short of how many there actually are.

If anyone has a more complete list i would be grateful, I have been plodding through the out of the box .cs item templates to find additional parameters:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ItemTemplates

Solution

  • From This Post

    You can use:

    $solutiondirectory$
    

    for the directory of the solution, you can then combine other parameters to get the path of the item template. If MSDN could provide a list of all the reserved parameters this would have saved me a good few hours.