Reputation: 5645
I want to use environment tag on my view (.NET Core 3 and VS 2019 latest update).
Just create a simple project and added the code shown below in my view (in header section), but when I run it, it loads both CSS files, why? I mean my machine has product environment variable and because of it, the code should just load the second .min.css
file - not both.
I tested my machine environment when I run .exe file on my project path \bin\Debug\netcoreapp3.0
and it shows "Hosting environment: Production", then what is wrong?
<environment include="Development">
<link rel="stylesheet" href="~/css/StyleSheet1.css" />
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="~/css/StyleSheet1.min.css" asp-append-version="true" />
</environment>
In Chrome inspector:
It must not load both processed CSS and unprocessed CSS files at the same time, am I wrong?
After a day searching I found that this is a simple work to do and just needed to add some environment tags on my view, it works good but why loading both files, it's weird.
Update 1:
I have two "Development" environment variables on my code but my real environment variable name is "Production", it means CSS file on the first section should not be load anymore but it does.
On the other hand when you remove second section of my codes, I mean this:
<environment exclude="Development">
<link rel="stylesheet" href="~/css/StyleSheet1.min.css"
asp-append-version="true" />
</environment>
It must loads nothing because environment name is "Development" on my code and real environment name is "Production" and the first section of my code are saying if environment variable name is "Development" load this CSS else don't do that.
Upvotes: 3
Views: 902
Reputation: 5645
After searching a lot I found I should add a file "_ViewImports.cshtml" on my view and add this codes on it:
@using WebApplicationTest
@using WebApplicationTest.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
I don't know why should I do this to handle this case but .net core team would handle by the better ways, In my mind it can be made newbie confuse.
Upvotes: 3
Reputation: 146
You should try names="Development"
instead of include="Development"
<environment names="Development">
<link rel="stylesheet" href="~/css/StyleSheet1.css" />
</environment>
<environment exclude="Staging,Production">
<link rel="stylesheet" href="~/css/StyleSheet1.min.css" asp-append-version="true" />
</environment>
Upvotes: 0