Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditions Don't Work With Multi Choices #7441

Open
chobo2 opened this issue Jan 11, 2024 · 5 comments
Open

Conditions Don't Work With Multi Choices #7441

chobo2 opened this issue Jan 11, 2024 · 5 comments

Comments

@chobo2
Copy link

chobo2 commented Jan 11, 2024

Product

Visual Studio

Describe The Bug

Hi

I am trying to do conditions on my multi select choices.

I found this example: https://github.com/dotnet/templating/wiki/Conditions

I copied it as is into my template

 "symbols": {
    "Platform": {
      "type": "parameter",
      "description": "The target platform for the project.",
      "datatype": "choice",
      "allowMultipleValues": true,
      "enableQuotelessLiterals": true,
      "choices": [
        {
          "choice": "Windows",
          "description": "Windows Desktop"
        },
        {
          "choice": "WindowsPhone",
          "description": "Windows Phone"
        },
        {
          "choice": "MacOS",
          "description": "Macintosh computers"
        },
        {
          "choice": "iOS",
          "description": "iOS mobile"
        },
        {
          "choice": "android",
          "description": "android mobile"
        },
        {
          "choice": "nix",
          "description": "Linux distributions"
        }
      ],
      "defaultValue": "MacOS|iOS"
    }
}

When I do this

#if (Platform == MacOS)
// MacOS choice flag specified here
#endif

Does not matter if I choose it or not it always seems to be fall.

I am using NET 8, Blazor 8 and Visual Studio 2022 if that makes any difference

To Reproduce

Follow steps in the link

dotnet Info

output

.NET SDK:
version: 8.0.100

Visual Studio Version

2022

Additional context

No response

@chobo2
Copy link
Author

chobo2 commented Jan 11, 2024

I seem to only be getting this issue when I try to use my template in VS 2022, when I use the cli it seems to work proper.

@sayedihashimi
Copy link
Member

Adding @phenning since you mentioned this is specific to VS2022.

@chobo2
Copy link
Author

chobo2 commented Jan 12, 2024

Adding @phenning since you mentioned this is specific to VS2022.

It could be other versions of VS but I don't have anything older but yes it just seems to be a problem going through VS and not through command line

@chobo2
Copy link
Author

chobo2 commented Jan 12, 2024

Okay I got a bit of time and uploaded the template to my github:

https://github.com/chobo2/VSTemplateExample

I installed the template by going to the folder and doing "dotnet new install ."

I created a project by going

dotnet new mynewcustomtemplate -o "test" --Platform MacOS 

 dotnet new mynewcustomtemplate -o "test"

The first command I expect to be able to go to Program.Cs and see this line

// MacOS choice flag specified here

second command I do not expect to see this (I removed MacOS from the default value)

I got the expected results in both of them.

I moved on to VS 2022 and did the same thing. I created a new project and checked MacOS and then I created another project without MacOS checked.

In both instances I did not see // MacOS choice flag specified here in Program.cs

Other things to note that I noticed

  1. When I create a new project based on my template and keep "place soultion and project in same directory" UNCHECKED

I get this folder structure of \Project1\Project1\Project1 It seems to create an extra "Project1" folder. When I do it on command line, I get \Project1\Project1 which seems correct to me as that is what other VS template do.

  1. With default Value, if I completely remove it in my template.json and go to the VS template, the first choice is still always checked.
  "choices": [
            {
              "choice": "Windows",
              "description": "Windows Desktop"
            },
            {
              "choice": "WindowsPhone",
              "description": "Windows Phone"
            },
            {
              "choice": "MacOS",
              "description": "Macintosh computers"
            },
            {
              "choice": "iOS",
              "description": "iOS mobile"
            },
            {
              "choice": "android",
              "description": "android mobile"
            },
            {
              "choice": "nix",
              "description": "Linux distributions"
            }
          ],
          "defaultValue": "iOS" // if I remove this line of just put an empty string in, in the VS 2022  project creation  "Windows" will become always checked.
        }

@chobo2
Copy link
Author

chobo2 commented Feb 6, 2024

Adding @phenning since you mentioned this is specific to VS2022.

Anyone have any updates on this if I am doing it wrong or if this is a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants