Search code examples
c#vsixvisual-studio-templates

use $if$ in visual studio template


Hi i am creating a vsix extension according to this tutorial. Somewhere I need to put a code if the variable value was True and another one if it was False

In this example, Microsoft used this $if$ command

$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;

I wrote a similar command but it didn't work

Console.WriteLine("$custommessage$"); // this line work fine and return a True value


string data = "$custommessage$"; // we have True value in data

$if$ (data.Equals("True"))
    Console.WriteLine("$custommessage$" + " This is True");
$endif$

Now I expect this piece of code

Console.WriteLine("$custommessage$" + " This is True");

to be generated when creating a new project, but there is no code


Solution

  • Template processing doesn't execute the code in the template.

    Meaning, (data.Equals("True")) is not run or executed.

    Processing a template, only evaluates macros like $targetframeworkversion$ or others that you might have added to the replacements dictionary via a custom IWizard.RunStarted method.

    Ed....