knightpfhor
knightpfhor

Reputation: 9399

What is the name of the web role .config file with SDK 2.2

I have a web role in which I have extended the RoleEntryPoint to do some work that is outside of the scope of the web site. As part of the RoleEntryPoint.Run() my code is required to read from the .config using ConfigurationManager.

While this is a little unusual, using SDK 1.8 I was able to make this work by ensuring that my package included a [The name of my project].dll.config file.

Now that I have upgraded to SDK 2.2 when I try to use .AppSettings or .GetSection() the values are always null, which leads me to believe it is unable to find my file.

I have tried deploying a Worker Role and the .config file still follows the same name pattern that I'm currently using.

I have also tried naming the file WaIISHost.exe.config.

I am aware that ideally this configuration should be included in the .csfg file, but my questions is does anyone know what I should be calling my config file?

UPDATE:

With the help of this question, I now know that the name of the config file it is reading from is E:\base\x64\WaIISHost.exe.Config, but I don't know why this has changed or what I can to overide this.

Upvotes: 1

Views: 810

Answers (3)

Le Zhang
Le Zhang

Reputation: 951

This page explained why it's called WaIISHost.exe.Config and where you can put it in your project. http://azure.microsoft.com/blog/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core/

Like knightpfhor mentioned, you can also use [AssemblyName].dll.config to put these configuration too. It depends on the assembly name of your project, you can check property of your web role project.

Upvotes: 0

knightpfhor
knightpfhor

Reputation: 9399

After much investigation and trial an error I finally have a solution.

The name of the file is still required to be [The name of my project].dll.config, but you need to make sure that this file is in your approot\bin\ directory of your package.

I believe my initial problem was caused by the Copy to Output Directory property being changed to Do Not Copy, although I'm unsure how this happened. If you find yourself in a similar situation you can just add a file with the correct name to your project and set the Copy to Output Directory to be Copy Always.

Once I'd done that however I realised I had another problem. I needed the .config file to have had the config transformations run over it, which this didn't do. To fix this I updated the .ccproj file to have the following:

<PropertyGroup>
    <!-- The first two of these targets are what is defined in the base SDK 2.2 targets file.  When we upgrade we may need to look reassess this. -->
    <CopyRoleFilesDependsOn>
        CopyWebRoleFiles;
        CopyWorkerRoleFiles;
        CopyWebConfigToBin;
    </CopyRoleFilesDependsOn>
</PropertyGroup>
<Target Name="CopyWebConfigToBin">
    <!-- We need to copy the transformed Web.config to the bin directory so that the RoleEntryPoint has access to the config settings.-->
    <Message Text="Copy %(WebRoleReferences.OutputDir)Web.config tp %(WebRoleReferences.OutputDir)\bin\BackOffice.UI.dll.config" Importance="high" />
    <Copy SourceFiles="%(WebRoleReferences.OutputDir)Web.config" DestinationFiles="%(WebRoleReferences.OutputDir)bin\[Name of project].dll.config" />
</Target>

This adds an extra target which waits until all of the other files have been copied to the appropriate directory and then picks up the web.config and puts a copy in the bin directory with the correct name.

Upvotes: 3

Evan
Evan

Reputation: 6123

Are you able to put the config values into the Azure config file (the .cscfg) rather than using the .config file? You can read the values from the cscfg via the RoleEnvironment.GetConfigurationSettingValue static method.

Upvotes: 1

Related Questions