我正在使用 Azure SDK 2.0 和 OS Family 3,对此我感到非常困惑。因此,我创建了一个 MVC 4.0 网站,其中包含各种答案中建议的所有 4 个配置文件。那是:
- 网页配置
- 应用程序配置
- WaIISHost.exe.config
- [程序集名称].dll.config
除了 Web.config 之外的所有内容都设置为“如果较新则复制”。
在我写的配置文件中:
<appSettings>
<add key="AppSettingFile" value="[NameOfConfigFile]"/>
</appSettings>
在 WebRole.cs 我有以下代码:
public class WebRole : RoleEntryPoint
{
public override void Run()
{
string appSetting = ConfigurationManager.AppSettings["AppSettingFile"] ?? "No config file found";
Trace.TraceInformation("Config file: " + appSetting);
while (true)
{
...
}
}
}
使用 4 个 .config 文件部署时的结果:
"Config file: App.config"。所以 App.config 一定是答案,对吧?
错误的!仅使用 Web.config 和 App.config 部署时的结果:
"Config file: No config file found"。嗯很奇怪。
使用 Web.config、App.config 和 [AssemblyName].dll.config 部署时的结果:
"Config file: [AssemblyName].dll.config"。所以 [AssemblyName].dll.config 一定是答案,对吧?
错误的!仅使用 Web.config 和 [AssemblyName].dll.config 部署时的结果:
"Config file: No config file found"。哇!
仅使用 Web.config 和 WaIISHost.exe.config 部署时的结果:
"Config file: No config file found"。
使用 Web.config、App.config 和 WaIISHost.exe.config 部署时的结果:
"Config file: No config file found"。哇!
所以我的结论是你需要有 3 或 4 个配置文件才能配置 Web 项目的 Worker 角色。
这显然是一个错误。就我个人而言,我认为 MS 的意图是从 WaIISHost.exe.config 更改为 App.config(通常与 Worker Roles 和 .NET 保持一致)。但 App.config 仅在所有 4 个 .config 文件都存在时使用。
所以现在我有 Web.config 以及 App.config 和 [AssemblyName].dll.config,它们包含完全相同的内容。
希望随着 Azure SDK 2.x 的发展,我们只能使用 App.config 和 Web.config。