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

calculated parameters #905

Closed
lucamorelli opened this issue Jun 7, 2017 · 5 comments
Closed

calculated parameters #905

lucamorelli opened this issue Jun 7, 2017 · 5 comments

Comments

@lucamorelli
Copy link

reading the https://blogs.msdn.microsoft.com/dotnet/2017/04/02/how-to-create-your-own-templates-for-dotnet-new/ I read this:

The expression used in the condition here, (EnableContentPage), is very basic but, you can create more complex conditions using operators such as &&,||,!,<,>=,etc. For more info see https://aka.ms/dotnetnew-template-config.

Looks like that I can create a complex condition inside the template, but since sometimes the expressions can be complicated and must replicated in more places in the template files, I would like to know if is possibile to move the definition and evalution of the expression outside the files itself in a single place.
I looked to the documentation and I don't understand if is possible: the more simple idea I have is to create some kind of parameter as a calculated field based on other paramters and conditions, and use this directly in the template files.

@sayedihashimi
Copy link
Member

Hi @lucamorelli I'm not really following the scenario. Can you be more specific?

@lucamorelli
Copy link
Author

if I need to add a condition like this
if ( Framework == 'netcoreapp2.0' && Authentication == 'Azure AD' && dataBaseType != 'SqlServer)

how can I express it in a more concise way ?

@sayedihashimi
Copy link
Member

I'm not sure if this is what you are looking for so let me know if it's not.

If you need to use a condition in several places I believe that a computed symbol is what you need. For example see how OrganizationalAuth is defined in here.

After creating that computed symbol you can use that in your if statements. So you can do

#if (OrganizationalAuth)
...
#endif

Example here

Instead of

#if (auth == \"SingleOrg\" || auth == \"MultiOrg\")
...
#endif

@lucamorelli
Copy link
Author

thanks, looks like it's what I was looking for. Can you add a sample about this in the samples repo? I looked for something similar, but I haven't found anything similar neither in the sample repo nor in the main branch of this repo

@sayedihashimi
Copy link
Member

I created dotnet/dotnet-template-samples#19 to track creating a sample for this.

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