sayedihashimi / template-sample

Other
232 stars 55 forks source link

Parameters are not showing up in VS2022 #49

Closed JohanPetersson closed 2 years ago

JohanPetersson commented 2 years ago

Not sure where to log these issues, please point me to correct repo if this is not the correct place.

Parameters are not showing up in VS2022. I install my template from a local NuGet package, I'm clearing the cache (.templateengine) between installs and also exit all VS instances before clearing the cache. I've also created an ide.host.json file with the parameters to see if that made any difference, but with no luck (the schema for ide.host.json seems to be outdated http://json.schemastore.org/vs-2017.3.host). All other changes I make to the template, such as new or changed files, does work. The template fulfills all other requirements you mention here.

These are my symbols in template.json

...
"symbols": {
  "enablelDocker": {
    "type": "parameter",
    "datatype": "bool",
    "defaultValue": "false",
    "description": "Enable Docker support"
  },
  "saPassword": {
    "type": "parameter",
    "datatype": "string",
    "defaultValue": "Qwerty12345!",
    "description": "Password for the SA database account",
    "replaces": "Qwerty12345!"
  }
}
...

and ide.host.json

...
"symbolInfo": [
  {
    "id": "enablelDocker",
    "name": {
      "text": "Enable Docker support"
    },
    "isVisible": "true"
  },
  {
    "id": "saPassword",
    "name": {
      "text": "Password for the SA database account"
    },
    "isVisible": "true"
  }
]
...

What have I missed?

sayedihashimi commented 2 years ago

There is some caching bug that I ran into recently. I’m thinking you are running into the same. You shouldn’t need an ide.host.json anymore for VS2022. Try this, uninstall your template, copy your template to another folder and then install from that new location. Does it work after that?

sayedihashimi commented 2 years ago

Filing bugs here for now is ok. After we figure it out we can move it if needed.

RehanSaeed commented 2 years ago

You shouldn’t need an ide.host.json anymore for VS2022.

@sayedihashimi I noticed that template.json had a new displayName for symbols, so I switched over to that instead of ide.host.json but I still use ide.host.json for isVisible. Are you saying everything is visible now by default and we don't need ide.host.json?

RehanSaeed commented 2 years ago

If true I think I still need ide.host.json for these settings:

{
  "order": 0,
  "learnMoreLink": "https://github.com/Dotnet-Boxed/Templates/blob/main/Docs/Orleans.md",
  "icon": "icon.png"
}

But can remove all symbolInfo:

"symbolInfo": [
    {
      "id": "Title",
      "isVisible": true
    },
    ...
]
JohanPetersson commented 2 years ago

Exited VS, cleared cache, uninstalled template, moved nupgk to different location, and installed. No difference. As I mentioned, other changes in the template do work, so I know that the some things are not cached at least.

Here's the complete template (with some info replaced with 'xxx')

{
  "$schema": "http://json.schemastore.org/template",
  "author": "xxx",
  "sourceName": "Cms.Empty",
  "classifications": [ "Web" ],
  "identity": "xxx",
  "name": "xxx",
  "shortName": "xxx-cms-empty",
  "description": "Empty web application with xxx CMS",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "sources": [
    {
      "modifiers": [
        {
          "condition": "(!enablelDocker)",
          "exclude": [
            "Directory.Build.props",
            "docker-compose.yml",
            "Docker/**/*"
          ]
        }
      ]
    }
  ],
  "symbols": {
    "enablelDocker": {
      "type": "parameter",
      "datatype": "bool",
      "defaultValue": "false",
      "description": "Enable Docker support"
    },
    "saPassword": {
      "type": "parameter",
      "datatype": "string",
      "defaultValue": "Qwerty12345!",
      "description": "Password for the SA database account",
      "replaces": "Qwerty12345!"
    }
  }
}

I've noticed all examples are using pascal casing on symbols, could that be the issue here?

sayedihashimi commented 2 years ago

@RehanSaeed

@sayedihashimi I noticed that template.json had a new displayName for symbols, so I switched over to that instead of ide.host.json but I still use ide.host.json for isVisible. Are you saying everything is visible now by default and we don't need ide.host.json?

No need for isVisible any more. By default all parameters will be displayed. You can create a host file to hide parameters if needed.

If true I think I still need ide.host.json for these settings:

For the learn more link, you'll need the host file. For the icon, you can drop the icon.png and it will get picked up. One thing that I'm not sure of, if you have a host file you may need to define the icon there. If you could try it and let me know that would be great. I can add that detail to the readme.

sayedihashimi commented 2 years ago

@JohanPetersson can you share your template? It will be much easier for me to diagnose it if I can try it. If you can't share it here, you can share it with me privately by emailing me at sayedha [AT] MICROSOFT.

JohanPetersson commented 2 years ago

I've emailed you Sayed. Thanks for taking your time and looking into this.

RehanSaeed commented 2 years ago

No need for isVisible any more. By default all parameters will be displayed. You can create a host file to hide parameters if needed.

I tried removing all symbols in ide.host.json but kept the file to set the order, learnMoreLink and icon properties and my symbols no longer show up in VS 2022 Preview except the Framework symbol.

sayedihashimi commented 2 years ago

I tried removing all symbols in ide.host.json but kept the file to set the order, learnMoreLink and icon properties and my symbols no longer show up in VS 2022 Preview except the Framework symbol.

@phenning is that expected with the current bits?

@JohanPetersson I have replied to your email, we can continue our discussion on email. For other folks looking at this issue, I believe Johan is running into this bug https://github.com/dotnet/templating/issues/4155.

phenning commented 2 years ago

The default if behavior if an ide.host.json is specified is to NOT opt in symbols which are not specified in symbolInfo by default.

However, you can add "defaultSymbolVisibility": trueto the host file to enable all the symbols even if no symbolInfo is configured. in the case where you don't need to override the text or defaults in Visual Studio. This can be combined with explictly adding a symbolInfo section and disabling certain symbols via isVisible: false, or modifying their default value or display text.

The complete behavior is as follows.

For no host file:

  1. Display all parameters by default unless vs_showParametersByDefault is set to false in the template.json tags. (This defaults to true if not specified)
  2. If vs_showParametersByDefault is not false, show the parameter unless it is contained within the semicolon delimited list contained in the tag "vs_parametersToHide"

If host file is present:

  1. If no symbolInfo is declared for the symbol, display it if it is not hidden via "vs_parametersToHide" AND if "defaultSymbolVisibility" is explictly set to true.
  2. If a symbolInfo is present, use isVisible if it is set, otherwise use defaultSymbolVisibility (in this case, if it is not set, we assume true since the symbolInfo was declared)
sayedihashimi commented 2 years ago

Thanks @phenning, I will get those details added to the readme here soon.

phenning commented 2 years ago

One note I found from the PR comment I made when I checked this in that may explain the complexity here:

"Note that we cannot treat defaultSymbolVisibility to be true in the cases when a symbol info is not present due to ASP.NET Core templates not specifically excluding most of their symbols."

We ended up erring on the side of not showing parameters if we thought existing templates could potentially expose too many parameters in Visual Studio and make the experience confusing for template consumers.

JohanPetersson commented 2 years ago

I'm happy with your answers and it has resolved my issues now. Closing the issue. Thank you so much.

sayedihashimi commented 2 years ago

For anyone that comes back, the issue was relating to caching. If you are installing with a folder path, workaround is to copy the folder to another folder and install. If you are installing via .nupkg file, change the version number. Hopefully we can get a better workaround soon.

sayedihashimi commented 2 years ago

@phenning when you have a chance, please review my changes to readme to ensure that I didn't misstate anything https://github.com/sayedihashimi/template-sample/commit/1d627e6489a065a21548d7c23a78843c32b14f07.

RehanSaeed commented 2 years ago

I've tried @phenning's suggestion and used "defaultSymbolVisibility": true in my ide.host.json files while removing all "isVisible": true. However, I'm finding that it only works (options show up in VS) for my NuGet template and not the other API, GraphQL and Orleans templates.

Am I doing something wrong, is there a bug?

phenning commented 2 years ago

@RehanSaeed is the NuGet template the only one with a framework symbol in template.json? Did the other templates work when the symbolInfos re explicit?

RehanSaeed commented 2 years ago

@phenning Yes thats correct!

phenning commented 2 years ago

Can you see if adding a Framework symbol to one of the other templates results in the expected behavior for the other symbols?

It looks like a bug which results in the Additional Information page being skipped if there is no Framework Symbol and zero explicitly enabled symbols.

You may also be able to just define a single symbolInfo for just one of your symbols in order to work around the bug. This would be instead of adding a Framework symbol.

RehanSaeed commented 2 years ago

@phenning Just tested and adding a Framework symbol does work. Adding a single symbolInfo also works and it doesn't matter if the symbolInfo.isVisible is true or false.

Post actions are not run in Visual Studio (any plans to change that???), so I ended up having to include some symbolInfo's to hide options to skip running them e.g. I have an option to skip opening a TODO.html file.

Gregory-Lange commented 1 year ago

So this is a closed item however i am having this same exact issues in VS for Mac. I have it updated to latest codeset, i have looked over many samples/tutorials/MS Docs and parameters will not show on the form when creating a project from a template.

template.json file

{
    "$schema": "http://json.schemastore.org/template",
    "author": "",
    "classifications": [ "Web" ],
    "identity": "",
    "name": "",
    "groupIdentity": "",
    "shortName": "mymvc",
    "sourceName": "Template.MVC",
    "tags": {
        "language": "C#",
        "type": "project"
    },
    "preferNameDirectory": true,
    "symbols": {
        "ClientId": {
            "type": "parameter",
            "dataType": "string",
            "displayName": "AzureAD Application (client) ID",
            "defaultValue": "00000000-0000-0000-0000-000000000000",
            "replaces": "__CLIENTID__"
        },
        "TenantId": {
            "type": "parameter",
            "dataType": "string",
            "displayName": "AzureAD Directory (tenant) ID",
            "defaultValue": "00000000-0000-0000-0000-000000000000",
            "replaces": "__TENANTID__"
        },
        "ClientSecret": {
            "type": "parameter",
            "dataType": "string",
            "displayName": "AzureAD Client Secret",
            "defaultValue": "00000~0000000000000000000000000000000000",
            "replaces": "__CLIENTSECRET__"
        },
        "ApiScopes": {
            "type": "parameter",
            "dataType": "string",
            "displayName": "API Scopes (space delimited)",
            "defaultValue": "user.read",
            "replaces": "__APISCOPES__"
        },
        "SkipRestore": {
            "type": "parameter",
            "datatype": "bool",
            "description": "If specified, skips the automatic restore of the project on create.",
            "defaultValue": "false"
        }
    },
    "postActions": [
        {
            "condition": "(!skipRestore)",
            "description": "Restore NuGet packages required by this project.",
            "manualInstructions": [
                { "text": "Run 'dotnet restore'" }
            ],
            "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
            "continueOnError": true
        }
    ]
}

ide.host.json file

{
"$schema": "http://json.schemastore.org/vs-2017.3.host",
    "name": { "text": "My MVC" },
    "description": { "text": "This will allow one to make an MVC application that has all the wire-ups to start an application." },
    "icon": "icon.png",
    "tags": [
        {
            "type": "platform",
            "add": [ "C#", "MVC", "AzureAD" ]
        }
    ],
    "symbolInfo": [
        {
            "id": "ClientId",
            "name": { "text": "Client Id" },
            "isVisible": true
        },
        {
            "id": "TenantId",
            "name": { "text": "Tenant Id" },
            "isVisible": true
        },
        {
            "id": "ClientSecret",
            "name": { "text": "Client Secret" },
            "isVisible": true
        },
        {
            "id": "ApiScopes",
            "name": { "text": "Azure AD Api Scopes (space delimited)" },
            "isVisible": true
        },
        {
            "id": "SkipRestore",
            "isVisible": false,
        }
    ]
}