CZEMacLeod / MSBuild.SDK.SystemWeb

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.
MIT License
151 stars 8 forks source link

IIS Express profile launchSettings.json does not add environment variables in the iisexpress.exe process #65

Closed morindo closed 7 months ago

morindo commented 1 year ago

Our current Web app csproj is currently using the great (and thank you so much) MSBuild.SDK.SystemWeb/4.0.88 Sdk and when we launch the IIS Express profile (in debug or without debugging) from VS 2022, it does add the environment variables to the iisexpress.exe process, is this normal? Notice that it is working with a default ASP.NET Core Web App default project.

This is our launchSettings.json


  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51867/",
      "sslPort": 44301
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": false,
      "environmentVariables": {  // This does not work
        "ASPNETCORE_ENVIRONMENT": "Development",
        "AAA": "BBB"
      }
    }
  }
}
CZEMacLeod commented 1 year ago

@morindo Thanks for flagging this. I've done some testing and it looks like whatever logic/code VS uses to launch IISExpress, does not add the environmentVariables when in the MSBuild.SDK.SystemWeb. It does not appear to be a difference relating to hosting dotnet core vs dotnet framework in IIS itself (which was actually my first though) but actually something in the launch code. This bit of code is built into VS itself, so I can't easily debug or find what/why it doesn't work as expected. I've also done a bit of testing with launchSettings.json / launch profiles for console apps, and it seems to work with both net6 and net48 (framework) and correctly set the environment variables as expected. (This is with commandName set to Project). I'll see if I can dig into this a bit more, but it might need some help from the VS team here.

morindo commented 1 year ago

Thank you very much @CZEMacLeod for the quick response. Good hunch, I'll look into-it myself. I'll post if I find something.

swissarmykirpan commented 7 months ago

@morindo @CZEMacLeod any progress on this?

morindo commented 7 months ago

@swissarmykirpan unfortunately, I didn't find a way to make IISExpress use the launchSettings.json environment variable.

julealgon commented 3 months ago

Ran into this behavior today. @CZEMacLeod should this be tagged with the known limitation label?

Additionally, is there any known workarounds to this issue besides just forcing a system-wide environment variable?