[英]Why do environmentVariables from launchSettings.json profiles not load when aspNetCore web.config sections exist?
We recently upgraded a .NET Core 2.1 Web App to .NET 3.1.我们最近将 .NET Core 2.1 Web App 升级到 .NET 3.1。 Ever since, our profiles in launchSettings.json are not properly working.
从那以后,我们在 launchSettings.json 中的配置文件无法正常工作。 Specifically, the environmentVariables are not loading, with one in particular being "ASPNETCORE_ENVIRONMENT".
具体来说,环境变量没有加载,特别是“ASPNETCORE_ENVIRONMENT”。 We use this to switch appSettings.{Environment}.json when debugging locally to target different environments.
在本地调试以针对不同环境时,我们使用它来切换 appSettings.{Environment}.json。
In my research, it seems that the web.config is the culprit for this issue.在我的研究中,似乎 web.config 是这个问题的罪魁祸首。 For context, we keep a web.config in our project so we can customize some things for our deployments.
作为上下文,我们在项目中保留了 web.config,以便我们可以为我们的部署定制一些东西。 The profiles in question use IISExpress, therefore the web.config is taken into consideration.
有问题的配置文件使用 IISExpress,因此考虑了 web.config。
If I remove the web.config, I can switch launch profiles and they take effect.如果我删除 web.config,我可以切换启动配置文件并且它们生效。 However, when a web.config is present, the launch profile environment variables do not take effect.
但是,当 web.config 存在时,启动配置文件环境变量不会生效。
Now even more curious, if I remove just this section from the web.config, the environment variables from launch settings start to work again:现在更奇怪的是,如果我从 web.config 中删除这一部分,启动设置中的环境变量将再次开始工作:
This may be related to the Hosting Model changes going from OutOfProcess (.NET 2.1 default) to InProcess (.NET 3.1 default).这可能与 Hosting Model 从 OutOfProcess(.NET 2.1 默认)更改为 InProcess(.NET 3.1 默认)有关。 In fact, if we force the hostingModel for the project to OutofProcess, the launch profiles work as well, but we'd rather keep InProcess if possible.
事实上,如果我们强制项目的 hostingModel 为 OutofProcess,启动配置文件也可以工作,但如果可能,我们宁愿保留 InProcess。
So what's going on here?那么这里发生了什么? Are we missing some migration step?
我们是否缺少一些迁移步骤? We followed all the steps on MSDN, starting here and working up to 3.1: https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-3.1&tabs=visual-studio
我们遵循 MSDN 上的所有步骤,从这里开始直到 3.1: https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-3.1&tabs=visual -工作室
"environmentVariables": { "ASPNETCORE_ENVIRONMENT": "SomeTestValue" }
"environmentVariables": { "ASPNETCORE_ENVIRONMENT": "SomeTestValue" }
IWebHostEnvironment
in Configure
of Startup.cs.Configure
中IWebHostEnvironment
上的环境值。env.EnvironmentName
should match "SomeTestValue".env.EnvironmentName
应与“SomeTestValue”匹配。<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" stdoutLogEnabled="false" arguments="%LAUNCHER_ARGS%" hostingModel="inprocess" />
</system.webServer>
</configuration>
Holy moley, it was Visual Studio.天哪,它是 Visual Studio。 I was running VS 2019 16.6.2 and I JUST got the notification to update today to 16.6.3, but postponed it.
我正在运行 VS 2019 16.6.2 ,我刚刚收到今天更新到 16.6.3 的通知,但推迟了它。 Well, after researching all over stack, github, msdn, etc, I found these posts that lead me to see it was a bug in the 16.6.2 build of VS (possibly earlier versions as well), and the update that JUST came out fixes it.
好吧,在研究了整个堆栈、github、msdn 等之后,我发现这些帖子让我看到这是 VS 的 16.6.2 版本中的一个错误(也可能是早期版本),以及刚刚发布的更新修复它。
ASP.Net Core MVC needs <environmentVariables> in web.config to work ASP.Net Core MVC 需要 web.config 中的 <environmentVariables> 才能工作
which led to: https://github.com/dotnet/websdk/issues/564#issuecomment-644714341这导致: https://github.com/dotnet/websdk/issues/564#issuecomment-644714341
which led to this comment about the VS update: https://github.com/dotnet/websdk/issues/1510#issuecomment-652012087这导致了关于 VS 更新的评论: https://github.com/dotnet/websdk/issues/1510#issuecomment-652012087
The docs linked in that comment don't specifically mention this fix.该评论中链接的文档没有具体提及此修复程序。 I couldn't find the full release notes.
我找不到完整的发行说明。 https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.6.3
https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.6.3
But ANYWAYS, updating to VS 2019 16.6.3 worked.但无论如何,更新到 VS 2019 16.6.3 有效。 I can keep my aspNetCore web.config settings, and launch profile environment variables now load correctly.
我可以保留我的 aspNetCore web.config 设置,并且现在可以正确加载启动配置文件环境变量。 Huzzah!
嘘!
Talk about perfect timing for an update...谈论更新的最佳时机......
Also, many browser tabs and RAM bytes lost their lives in search for this answer.此外,许多浏览器选项卡和 RAM 字节在寻找这个答案时失去了生命。 Respect.
尊重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.