Why are all ASP.NET Core Environment sections being included?

I have an ASP.NET Core project in which I want to use the environment tag helpers with two sections being defined. I know about the ASPNETCORE_ENVIRONMENT variable. I can change that and I can see different code running in Startup.cs as a result.

However, it's not working in the environment tags. I have this set up.

<environment names="Development">
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/vuejs/vue.js"></script>
</environment>
<environment names="Staging,Production">
    <script src="~/lib/standard.min.js"></script>
</environment>

When I debug in Chrome, its showing me the source from all sections is being loaded, regardless of my ASPNETCORE_DEVELOPMENT setting. The 'elements' tab in Chrome debugger shows me that the two environment sections are being output in the html. I thought the intent was that only the relevant section would be output by ASP.NET Core in the view? How come I am getting both being output?

Upvotes: 3

Views: 603

Answers (1)

cpr43
cpr43

Reputation: 3112

You have to add @addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" to the file containing the html, or if you follow the setup of a default project add it to _ViewImports.cshtml.

Upvotes: 6

Related Questions