2

I am attempting to create a custom Visual Studio project template and I have a template.json. What I am trying to achieve is to hide / disable the DoStuff parameter from the Visual Studio create project wizard if another parameter (in my case, ProjectType) was equal to something specific. It would essentially be something like the Docker OS parameter from the default Visual Studio API template.

VS create project wizard

As you can see, by default the dropdown (in my case, it would be a checkbox) is hidden / disabled, but if I check Enable Docker, it can be selected.

Below is my current template.json file which I can't seem to get right to have this feature.

{
    "$schema": "http://json.schemastore.org/template",
    "symbols": {
      "ProjectType": {
        "type": "parameter",
        "datatype": "choice",
        "choices": [
          {
            "choice": "Console"
          },
          {
            "choice": "API"
          }
        ],
        "defaultValue": "API",
        "description": "The type of the project you are building."
      },
      "DoStuff": {
        "type": "parameter",
        "datatype": "bool",
        "defaultValue": "false",
        // hide if ProjectType == API
      }
    }
}

I tried to combine it with ide.host.json to achieve this, but it's not working at all.

{
    "$schema": "https://json.schemastore.org/ide.host.json",
    "defaultSymbolVisibility": true,
    "order": 2,
    "icon": "icon.png",
    "symbolInfo": [
      {
        "id": "DoStuff",
        "isVisible": "(ProjectType == \"API\")"
      }
    ]
}
TheDoomDestroyer
  • 2,434
  • 4
  • 24
  • 45

1 Answers1

2

After some more investigation and contacting Sayed Ibrahim Hashimi (sayedihashimi) on Twitter, it turns out this is currently not supported and there's likely no way to achieve it right now in .NET 6 and prior releases.

However, as per Chet Husk's (@ChetHusk) template engine upgrades comment (which redirects you to Github:dotnet/templating/docs/Conditions.md), templating conditions will be a feature added to .NET 7. The dotnet new cli already supports it, but the Visual Studio support has not yet been started on.

TheDoomDestroyer
  • 2,434
  • 4
  • 24
  • 45
  • Did you succeed? I followed the doc: VS 17.4.4 installed with .net 7 and can use "isEnabled" key within template.json but it doesn't do anything. – Sinan Feb 03 '23 at 22:51
  • I had tried it back in November, but from what I remember, it didn't work. Might be a good idea to ping Sayed on Twitter again. Maybe they delayed the Visual Studio inclusion. – TheDoomDestroyer Mar 14 '23 at 22:19