简体   繁体   English

组合的Azure Web角色和辅助角色项目在部署时未看到app.config

[英]Combined Azure web role and worker role project not seeing app.config when deployed

I'm implementing the combined web/worker role scenario as described here where you simply add the following to your worker role: 我正在实现此处所述的组合Web /辅助角色方案,您只需将以下内容添加到您的辅助角色:

public override void Run()
{
    // This is a sample worker implementation. Replace with your logic.
    Trace.WriteLine("WorkerRole1 entry point called", "Information");
    while (true)
    {
        Thread.Sleep(10000);
        Trace.WriteLine("Working", "Information");
    }
}

The problem, as noted in the post's comments, is that this worker process cant read web.config so you have to add an app.config. 正如帖子的评论中所指出的那样,问题在于此工作进程无法读取web.config,因此您必须添加app.config。 It is also noted that app.config does not get deployed automatically. 还注意到app.config不会自动部署。

So my question is how do I configure my project so app.config will get deployed? 所以我的问题是如何配置我的项目,以便部署app.config?

I've added app.config to my project, set the Build Action to "Content", and "Copy always" 我已将app.config添加到我的项目中,将Build Action设置为“Content”,然后“始终复制”

THIS WORKS FINE IN THE EMULATOR, but not when deployed to Azure. 这项工作在EMULATOR中很精细,但在部署到Azure时却没有。

Note: I noticed in the emulator a projectname.dll.config is created, but not when deployed to Azure. 注意:我注意到在模拟器中创建了一个projectname.dll.config,但是在部署到Azure时却没有。 I'm using VS2010, Windows Azure Tools 2011 我正在使用VS2010,Windows Azure Tools 2011

I know some will suggest using the .cscfg file instead, but many of my components get their settings from web.config/app.config: Elmah, Transient Fault Handling Client, Diagnostics, Email, etc... 我知道有人会建议使用.cscfg文件,但我的许多组件都从web.config / app.config获取设置:Elmah,Transient Fault Handling Client,Diagnostics,Email等...

Please read thoroughly this blog post . 请仔细阅读此博文 It explains in great details what is happening in Windows Azure Web Role with Full IIS. 它详细解释了Windows Azure Web角色与完整IIS中发生的情况。

What you need to do, is to add a WaIISHost.exe.config file (with copy to output = copy always). 你需要做的是添加一个WaIISHost.exe.config文件(复制到output = copy总是)。 And put all the configurations you need in that file. 并将所需的所有配置放在该文件中。 This is because, your code (RoleEntryPoint) lives in WaIISHost.exe process, and not your pdojectName.dll process. 这是因为,您的代码(RoleEntryPoint)存在于WaIISHost.exe进程中,而不是您的pdojectName.dll进程。

For me using Azure SDK 1.8 and deploying my Web Worker Role from the Visual Studio using publish, I had to include a config file, named. 对于我使用Azure SDK 1.8并使用发布从Visual Studio部署我的Web Worker角色,我必须包含一个名为的配置文件。 ProjectName.Dll.config with my settings. 使用我的设置的ProjectName.Dll.config。 The configuration from app.config is not picked up by the web role when running in windows azure. 在windows azure中运行时,web角色无法获取app.config中的配置。 And the app.config file is not converted into a ProjectName.Dll.config and added automatically to the bin folder of the deployment package, so you have to create it by hand and set it to copy always. 并且app.config文件未转换为ProjectName.Dll.config并自动添加到部署包的bin文件夹中,因此您必须手动创建它并将其设置为始终复制。

I'm using Azure SDK 2.0 and OS Family 3, and has been very confused about this. 我正在使用Azure SDK 2.0和OS Family 3,并且对此非常困惑。 So I created a MVC 4.0 website with all 4 config files suggested in various answers. 所以我创建了一个MVC 4.0网站,其中包含各种答案中建议的所有4个配置文件。 That is: 那是:

  • Web.config Web.config文件
  • App.config App.config中
  • WaIISHost.exe.config WaIISHost.exe.config
  • [AssemblyName].dll.config [的AssemblyName] .dll.config

All but Web.config was set to "Copy if newer". 除了Web.config之外的所有内容都设置为“如果更新则复制”。

In the configs file I wrote: 在configs文件中我写道:

  <appSettings>
    <add key="AppSettingFile" value="[NameOfConfigFile]"/>
  </appSettings>

In the WebRole.cs I have the following code: 在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)
            {
                ...
            }
        }
    }

Result when deployed with 4 .config files: "Config file: App.config" . 使用4 .config文件部署时的结果: “配置文件:App.config” So App.config must be the answer, right? 所以App.config必须是答案,对吧?

Wrong! 错误! Result when deployed with only Web.config and App.config: "Config file: No config file found" . 仅部署Web.config和App.config时的结果: “配置文件:找不到配置文件” Hmm wierd. 嗯很奇怪。

Result when deployed with Web.config, App.config and [AssemblyName].dll.config: "Config file: [AssemblyName].dll.config" . 使用Web.config,App.config和[AssemblyName] .dll.config部署的结果: “配置文件:[AssemblyName] .dll.config” So [AssemblyName].dll.config must be the answer, right? 所以[AssemblyName] .dll.config必须是答案,对吧?

Wrong! 错误! Result when deployed with only Web.config and [AssemblyName].dll.config: "Config file: No config file found" . 仅使用Web.config和[AssemblyName] .dll.config部署的结果: “配置文件:找不到配置文件” WTF! WTF!

Result when deployed with only Web.config and WaIISHost.exe.config: "Config file: No config file found" . 仅部署Web.config和WaIISHost.exe.config时的结果: “配置文件:找不到配置文件”

Result when deployed with Web.config, App.config and WaIISHost.exe.config: "Config file: No config file found" . 使用Web.config,App.config和WaIISHost.exe.config部署的结果: “配置文件:找不到配置文件” WTF! WTF!

So my conclusion is that you need to have 3 or 4 config files to be able to configure the Worker role of a Web project. 所以我的结论是你需要有3个或4个配置文件才能配置Web项目的Worker角色。

This is clearly a bug. 这显然是一个错误。 Personally I think the intention from MS was to change from WaIISHost.exe.config to App.config (to align with Worker Roles and .NET in general). 就个人而言,我认为MS的意图是从WaIISHost.exe.config更改为App.config(通常与Worker Roles和.NET一致)。 But App.config is only used when all 4 .config files exists. 但App.config仅在所有4个.config文件都存在时使用。

So for now I'm having Web.config and both App.config and [AssemblyName].dll.config, and they contain exactly the same. 所以现在我有Web.config以及App.config和[AssemblyName] .dll.config,它们包含完全相同的内容。

Hopefully going forward with Azure SDK 2.x we can use only App.config and Web.config. 希望继续使用Azure SDK 2.x,我们只能使用App.config和Web.config。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM