2019-09-11
Why does the environment tag helper work on my machine but not on Azure?
stackoverflow
Question

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:

  • Tried changing the value in azure config - no change.
  • Originally we had names, changed to include - no change. Still works on dev machine.

What is going on here?! Is this not what other people do?

Answer
1

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.

Why does the environment tag helper work on my machine but not on Azure?
See more ...