1

I have the following configuration, but the ASPNETCORE_ENVIRONMENT variable doesn't make it to the CsProj config.

.vscode/launch.json

{
    // Use IntelliSense to find out which attributes exist for C# debugging
    // Use hover for the description of the existing attributes
    // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/Web/bin/Debug/net5.0/Web.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Web",
            "stopAtEntry": false,
            // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        }
    ]
}

.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Web/Web.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/Web/Web.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/Web/Web.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

Web/Properties/launchSettings.json

{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:15269",
            "sslPort": 44386
        }
    },
    "profiles": {
        "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true
        },
        "Web": {
            "commandName": "Project",
            "dotnetRunMessages": "true",
            "launchBrowser": true,
            "applicationUrl": "https://localhost:5001;http://localhost:5000"
        }
    }
}

Web/Web.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
    <Target Name="PreCompile" BeforeTargets="Build">
        <Exec Command="$(MSBuildStartupDirectory)/node_modules/.bin/gulp build --environment $(ASPNETCORE_ENVIRONMENT)" />
    </Target>
</Project>
// gulpFile.ts
export { default as build } from './build/Sass';

// build/Sass.ts
import type { TaskFunction } from 'gulp';
import { dest, src } from 'gulp';
import * as fiber from 'fibers';
import * as sass from 'gulp-dart-sass';


const environment = process.argv[3] === '--environment' ? process.argv[4] : 'Staging';


const task: TaskFunction = () => {

    console.log(`Hello!!!!! ${environment}`);

    console.log(process.env);

    return src('./Web/themes/**/*.sass')
        .pipe(sass({ fiber }))
        .pipe(dest('./Web/wwwroot/themes'));
};


export default task;

Output

 Executing task: dotnet build /.../Web/Web.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Web -> /.../Web/bin/Debug/net5.0/Web.dll
  Web -> /.../Web/bin/Debug/net5.0/Web.Views.dll
  [17:50:28] Requiring external module ts-node/register
  [17:50:28] Working directory changed to ~/...
  [17:50:30] Using gulpfile ~/.../gulpfile.ts
  [17:50:30] Starting 'build'...
  Hello!!!!! undefined
  {
    TERM_PROGRAM: 'vscode',
    TERM: 'xterm-256color',
    SHELL: '/bin/zsh',
    TMPDIR: '/var/folders/pf/rmb77nvd2t99vjmq9z1xc6100000gn/T/',
    TERM_PROGRAM_VERSION: '1.52.1',
    DOTNET_HOST_PATH: '/usr/local/share/dotnet/dotnet',
    ORIGINAL_XDG_CURRENT_DESKTOP: 'undefined',
    LC_ALL: 'en_US.UTF-8',
    DOTNET_CLI_TELEMETRY_SESSIONID: 'f3d95a71-5185-4c74-b373-da49d9b6f174',
    USER: 'roydukkey',
    COMMAND_MODE: 'unix2003',
    MSBuildLoadMicrosoftTargetsReadOnly: 'true',
    SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.JpMQQSNA9S/Listeners',
    __CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x0',
    PATH: '/usr/local/php5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands',
    __CFBundleIdentifier: 'com.microsoft.VSCode',
    PWD: '.../Web',
    LANG: 'en_US.UTF-8',
    MSBuildSDKsPath: '/usr/local/share/dotnet/sdk/5.0.101/Sdks',
    XPC_FLAGS: '0x0',
    XPC_SERVICE_NAME: '0',
    SHLVL: '1',
    HOME: '...',
    VSCODE_GIT_ASKPASS_MAIN: '/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js',
    LOGNAME: 'roydukkey',
    VSCODE_GIT_IPC_HANDLE: '/var/folders/pf/rmb77nvd2t99vjmq9z1xc6100000gn/T/vscode-git-8f8e32c0ee.sock',
    GIT_ASKPASS: '/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh',
    VSCODE_GIT_ASKPASS_NODE: '/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer)',
    COLORTERM: 'truecolor',
    MSBuildExtensionsPath: '/usr/local/share/dotnet/sdk/5.0.101/',
    _: '.../node_modules/.bin/gulp',
    INIT_CWD: '.../Web'
  }
  [17:50:30] Finished 'build' after 71 ms

Terminal will be reused by tasks, press any key to close it.
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Using launch settings from '/.../Web/Properties/launchSettings.json' [Profile 'Web']...
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Private.CoreLib.dll'.
Loaded '/.../Web/bin/Debug/net5.0/Web.dll'. Symbols loaded.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Hosting.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/netstandard.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Hosting.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Hosting.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.DependencyInjection.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.DependencyInjection.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Collections.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.ComponentModel.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.IO.FileSystem.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Hosting.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.EnvironmentVariables.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Threading.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Linq.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Server.Kestrel.Core.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Server.Kestrel.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Server.IIS.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.InteropServices.RuntimeInformation.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Server.IISIntegration.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.CommandLine.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.Core.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.FileProviders.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.FileProviders.Physical.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Memory.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.FileExtensions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.Binder.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.Json.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Configuration.UserSecrets.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.InteropServices.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.IO.FileSystem.Watcher.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.ComponentModel.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Collections.Concurrent.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.FileSystemGlobbing.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Threading.Thread.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Text.Json.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Text.Encoding.Extensions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Numerics.Vectors.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.CompilerServices.Unsafe.dll'. Module was built without symbols.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Options.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.EventLog.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.Configuration.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Options.ConfigurationExtensions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.Console.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.Debug.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Logging.EventSource.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Diagnostics.Tracing.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Diagnostics.DiagnosticSource.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Http.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Http.Features.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Http.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Connections.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Net.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Hosting.Server.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.HostFiltering.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.HttpOverrides.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Routing.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.ObjectPool.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Routing.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.ObjectModel.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.Loader.dll'.
Loaded '/.../Web/bin/Debug/net5.0/Web.Views.dll'. Symbols loaded.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Razor.Runtime.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.Razor.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Authentication.Core.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Authentication.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Security.Claims.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Authorization.Policy.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Authorization.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.DataAnnotations.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.RazorPages.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Razor.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.ViewFeatures.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Linq.Expressions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Components.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.JSInterop.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.DataProtection.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.DataProtection.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Cryptography.Internal.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Antiforgery.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.WebEncoders.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Text.Encodings.Web.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.Intrinsics.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Caching.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Caching.Memory.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Mvc.TagHelpers.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Extensions.Localization.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Threading.ThreadPool.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.Extensions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Console.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Threading.Tasks.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/Microsoft.Win32.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Xml.XDocument.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Private.Xml.Linq.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Private.Xml.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/Microsoft.Win32.Registry.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/System.IO.Pipelines.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Security.Cryptography.Algorithms.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Private.Uri.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Text.RegularExpressions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Reflection.Emit.ILGeneration.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Reflection.Emit.Lightweight.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Reflection.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Security.Cryptography.Primitives.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Diagnostics.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.HttpsPolicy.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.StaticFiles.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.Net.Http.Headers.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.ComponentModel.TypeConverter.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Collections.Specialized.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Html.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Metadata.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Diagnostics.Abstractions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Security.Cryptography.X509Certificates.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Collections.NonGeneric.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Formats.Asn1.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Security.Cryptography.Encoding.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Runtime.Numerics.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Net.Security.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Net.Sockets.dll'.
Microsoft.Hosting.Lifetime: Information: Now listening on: https://localhost:5001
Microsoft.Hosting.Lifetime: Information: Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
Microsoft.Hosting.Lifetime: Information: Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
Microsoft.Hosting.Lifetime: Information: Hosting environment: Development
Microsoft.Hosting.Lifetime: Information: Content root path: /.../Web
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /.../Web
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.ComponentModel.Annotations.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.WebUtilities.dll'.
Loaded 'Anonymously Hosted DynamicMethods Assembly'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.1/Microsoft.AspNetCore.Http.Extensions.dll'.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/System.Net.WebSockets.dll'.
roydukkey
  • 3,149
  • 2
  • 27
  • 43

4 Answers4

1

TL;DR

Change the build task inside tasks.json to

         {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "options": {
                "env": {
                    "ASPNETCORE_ENVIRONMENT":"development"
                }
            },
            "args": [
                "build",
                "${workspaceFolder}/Web/Web.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },

Explanation

The environment variables (ENVs) set inside Launch Targets of launch.json are passed to program only, and not to any of the launch tasks.
i.e. those ENVs are passed to ${workspaceFolder}/Web/bin/Debug/net5.0/Web.dll only, and not to the build task inside preLaunchTask.
FYI, building your project (.csproj) is being done by dotnet build & not msbuild, there are slight differences.
Anyways, this build is initiated by the preLaunchTask (build).
So if you want the ENVs to be passed to the project builder ( and in turn to the gulp program), then you need some way to pay those to the build task, specified in tasks.json ENVs can be passed to the tasks via options property. https://code.visualstudio.com/docs/editor/tasks#_custom-tasks

And no... you can't reuse the ENV variable like this

"env": {
    "ASPNETCORE_ENVIRONMENT":"${env:ASPNETCORE_ENVIRONMENT}"
}

Reason is as specified above; that ENVs from Launch Targets are not passed to the tasks.

gliesefire
  • 616
  • 5
  • 12
  • I just tried this, seems correct. Do you happen to why the process was designed this way? Seems like somethings missing, no? – roydukkey Jan 23 '21 at 17:42
  • 1
    I can speculate a reason, but no, I don't have any reputable source to back it up. Most probable reason, is that the `launch.json` is specific to [omisharp](https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md) While the [tasks](https://code.visualstudio.com/docs/editor/tasks) inside `tasks.json` are common to all, it is a feature of vscode itself. So what you are essentially requesting, is passing an extension specific configuration to the host program itself, which I don't think is a valid flow; that basically creates an inverse dependency – gliesefire Jan 23 '21 at 18:10
0

I think you might need to move the environment variable from env in your .vscode/launch.json file to environmentVariables in the "Web" property in Web/Properties/launchSettings.json.

learn.microsoft.com reference

Shafiq Jetha
  • 1,337
  • 16
  • 30
  • @roydukkey That's odd. I don't know Gulp well enough but are you certain that it's being called correctly from your Web.csproj file? – Shafiq Jetha Jan 14 '21 at 03:37
  • This what I've used to source my code. https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification?view=aspnetcore-5.0#run-gulp-tasks https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-environment-variables-in-a-build?view=vs-2019#to-use-an-environment-variable-in-an-msbuild-project – roydukkey Jan 14 '21 at 18:42
0

I think try adding another args element containing "/p:ASPNETCORE_ENVIRONMENT=$(ASPNETCORE_ENVIRONMENT)" in your tasks.json invocations?

Looking at the output of process.env it looks as if the invocation environment of dotnet.exe isn't inheriting the environment variables from VSCode.

jjee
  • 225
  • 1
  • 6
  • Didn't work. Tried `/p:ASPNETCORE_ENVIRONMENT=${env:ASPNETCORE_ENVIRONMENT}` as per https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables. Didn't work either. – roydukkey Jan 19 '21 at 19:44
  • apologies for wrong syntax. The environment pipeline seems to be - Code.exe -> dotnet.exe -> MSBuild.exe -> gulp You've shown that gulp doesn't have the ASPNETCORE_ENVIRONMENT set (process.env) - it seems that VSCode isn't supplying it into the environment of dotnet.exe. I would try setting ASPNETCORE_ENVIRONMENT in your shell then invoking dotnet.exe directly in that shell to verify, I suspect this will identify Code.exe as not supplying the env as it should. – jjee Jan 20 '21 at 13:12
  • That is sort of correct. Rather, I believe `dotnet.exe` is not passing the variable to `MSBuild.exe`, since the environment does change in the output, when changing the value in `launch.json` > `Microsoft.Hosting.Lifetime: Information: Hosting environment: Development` – roydukkey Jan 22 '21 at 18:46
0

Despite passing the environment variable or not, it seems to me that you are trying to run the program in Development mode, right? You seem to be succeeding in doing that, since the hosting environment is shown in the last output window to be Development in fact. So, if this is your goal, perhaps it is solved per si.

On the other hand, you could find useful to define the ASPNETCORE_ENVIRONMENT variable for production uses. If this is the case, defining it in MSBuild may not be what you want, nor absolutely is defining in the launchSettings.json, since this is used only for development purposes. So, I think that defining it as environment variable in the environment you want to run the app would be a good option - then, whether the value is Development, Staging or Production is up to the deployment pipeline.

However, please note that, if you do not want to access the ASPNETCORE_ENVIRONMENT variable itself, you may actually do not need to define it. The default hosting environment of a published app is Production, and it only changes when the environment variable is provided (here).

This reference has pretty good information on this topic :)

nunohpinheiro
  • 2,169
  • 13
  • 14
  • I just want to be able to switch the whole stack from `'Development'` and `'Production'` in ONE location. Since `launch.json` is at the top of the stack, and since EnvVars are configurable there, I don't see why my expectation is unreasonable. – roydukkey Jan 23 '21 at 05:49
  • Ok, understood :) Well, that file is used only when running from VS Code, it is not used in any other situation; that kind of files is ignored when you publish the application. That's why I think it is better to handle the variable at the "machine" level. Also, that is only an environment variable that influences the host environment mode; however, you may change the environment mode without setting the `ASPNETCORE_ENVIRONMENT` variable (based on what you showed, I think that you are only verifying the environment mode, not the variable). – nunohpinheiro Jan 23 '21 at 08:57
  • With this said, if you want to try to set the variable or the environment when performing `dotnet run`, you may follow the ansewrs [here](https://stackoverflow.com/questions/37322565/dotnet-run-or-dotnet-watch-with-development-environment-from-command-line). If you only want to debug stuff on the run, in case you are in a Windows machine, you may want to try the Visual Studio IDE (Community edition is free) instead of the Code, since this becomes much easier – nunohpinheiro Jan 23 '21 at 09:05