Mvc: Alternative for Environment TagHeper domain

Created on 9 Jan 2017  Â·  8Comments  Â·  Source: aspnet/Mvc

_From @vkichline on October 8, 2015 22:32_

I see this pattern in the Web Application template's _ValidationScriptsPartial.cshtml:

<environment names="Development">
       …
</environment>
<environment names="Staging,Production">
       …
</environment>

This pattern above seems brittle; if I add a new environment setting, I have a lot of searching and modification to do.

I wish I had something like:

<environment names="Development">
       …
</environment>
<environment names="!Development">
       …
</environment>

…or:

<environment names="Development">
       …
<else>
       …
</environment>

_Copied from original issue: aspnet/Razor#567_

3 - Done enhancement

Most helpful comment

maybe:

<environment include="Development">
    ...
</environment>
<environment exclude="Development">
    ...
</environment>

And keep support for names as it is now.

All 8 comments

The <else> thing can't be done because it's not valid syntax.

But something like this can certainly be done:

<environment names="Development">
    <true>
       …
    </true>
    <false>
       …
    </false>
</environment>

(Not saying it's worth it or that it's a good idea, but it's implementable.)

Another alternative to consider would be something like:

<environment names="Development">
       …
</environment>
<environment names="Development" behavior="OppositeDay">
       …
</environment>

Or at least something like that.

Another option to consider:

Another alternative to consider would be something like:

<environment names="Development">
       …
</environment>
<environment excludeNames="Development">
       …
</environment>

And you can't set both names and excludeNames.

@DamianEdwards thoughts on this? I think this could clean up the default templates. And, of course, Hubbup.

maybe:

<environment include="Development">
    ...
</environment>
<environment exclude="Development">
    ...
</environment>

And keep support for names as it is now.

Yeah I dig this. @danroth27 totally digs this too.

Let's go with @DamianEdwards 's suggestion in https://github.com/aspnet/Mvc/issues/5671#issuecomment-272021274.

@Eilon @DamianEdwards or maybe

options are may

<environment>
<case names="..." include=true>
</case>
<case names="..." include=false>
</case>
<default>
</default>
</environment>
Was this page helpful?
0 / 5 - 0 ratings