Reputation: 793
This is a section on our _Layout.cshtml that I'm about to throw out the window.
<!-- CSS Scripts -->
<environment include="Development">
<script src="/ts/CS.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
<script src="/ts/CS.Url.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
<script src="/ts/CS.Settings.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
<script src="/ts/CS.Alert.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
<script src="/ts/CS.Modal.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
</environment>
<environment include="Staging,Production">
<script abp-src="/ts/CS.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script>
</environment>
We use the environment tag helper in some spots to either use .min.js or .js, useful for debugging. I can see that if I personally set the ASPNETCORE_ENVIRONMENT
variable from "Development" to "Production" that the tag helper continues to render the right content.
However, when I then push this through to be hosted on Azure - the content is missing completely.
Things I've tried:
names
, changed to include
- no change. Still works on dev machine.What is going on here?! Is this not what other people do?
Upvotes: 1
Views: 1538
Reputation: 4253
I was having the same issue with asp.net 3.0. It was rendering environment on local properly but when I deployed to Azure it stopped detecting it and rendering both the environment as it is.
Here is the solution. Just add the below line in your _Layout.cshtml file in the beginning.
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
thanks
Upvotes: 2
Reputation: 21526
The exclude="Development"
works if you want to apply the same settings to all other environment except Development
. But I came across a time when I need to have different settings for staging and production. So I had to be specific.
The solution I use in order for the environment tag helper to work on Azure is that you need to create an entry for the ASPNETCORE_ENVIRONMENT
under Settings -> Configuration -> Application settings on Azure:
If you don't have that defined on Azure, when you publish, it will default to Production if I remember correctly, which is weird.
Upvotes: 2
Reputation: 330
Staging, production is not understandable to the server. You need to change this as follow.
If You are working in local than our script will work which is inside
<environment include="Development">
</environment>
if You are working on server like azure and others than our script will work which is inside
<environment exclude="Development">
</environment>
You need to change your following code
<environment include="Staging,Production">
<script abp-src="/ts/CS.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script> </environment>
as
<environment exclude="Development">
<script abp-src="/ts/CS.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
<script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script>
</environment>
It will work at any server.
Upvotes: 1