I was curious if there is a way to make my scripts conditional based on the environment? I've seen some examples similar to mine but for some reason the scripts do not render when published.
_ViewImports
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
Layout (does work)
@RenderSection("Styles", false)
@{
if (@Configuration["ASPNETCORE_ENVIRONMENT"] == "Development")
{
<link href="~/css/test.css" rel="stylesheet" asp-append-version="true" />
}
else
{
<link href="~/css/test.min.css" rel="stylesheet" asp-append-version="true" />
}
}
View (what doesn't work)
@* @{
if (@Configuration["ASPNETCORE_ENVIRONMENT"] == "Development")
{
@section Styles {
<link rel="stylesheet" href="~/css/Folder/file.css" asp-append-version="true"/>
}
}
else
{
@section Styles {
<link rel="stylesheet" href="~/css/Folder/file.min.css" asp-append-version="true"/>
}
}
} *@
If I only pass Folder/file.min.css or Folder/file.css within the @section Styles they render. So I know both file versions exist; however, for some reason if @section is inside the @{} it doesn't render.
Note: Configuration value is inside my appsettings-development-json and I have confirmed both in debug and publish that the value is returned correctly.


