Web Deployment Project questions

Last post 11-23-2005 2:22 PM by alurch. 2 replies.

Sort Posts:

  • Web Deployment Project questions

    11-22-2005, 7:29 PM
    • Member
      20 point Member
    • alurch
    • Member since 10-04-2004, 8:47 AM
    • Indianapolis, IN
    • Posts 4
    First, let me start by saying a huge Thank You for the Web Deployment Project!  It's already making my life much much easier.

    That said, I have two questions/problems I am running into, and they are slightly related.

    First, I have several projects set up which include a few class libraries, a website project, and a web deployment project.  Two of the class libraries make use of web services, and have a dynamic binding ("URL Behavior" is set to "Dynamic").  This places the url reference into an app.config file specific to that project.  My problem is that when those class libraries are used in the website project, the configuration settings are never discovered in the app.config files, presumably because the website only looks to the web.config for configuration (I could easily be way off on that).   If I copy the configuration information from the app.config files into the web.config file, the application picks up those settings and behaves as it should. If I leave them in their app.config files (no matter where those files are located), it ignores them.  Perhaps this is a side-effect of shadow copying the assemblies into the temporary ASP.NET folder? I don't know for sure...

    That's my first question (about how to get those settings to register without having to copy them manually into the web.config), and my second question is related.  As a work-around for the above, I figured that I would use the web.config file section replacement feature of the Web Deployment Project to automatically pull the "applicationSettings" section containing the web service URLs from another config file I maintain into the web.config file.  However the build continually fails indicating that the web.config file does not contain an "applicationSettings" section--even though I specifically added one.  Any ideas on that? I can post any samples regarding this if it would help.

    Thanks so much in advance!
  • Re: Web Deployment Project questions

    11-23-2005, 1:45 PM
    • Participant
      1,171 point Participant
    • BradleyB
    • Member since 11-06-2002, 3:53 PM
    • Posts 227
    • AspNetTeam

    The problem you’re running into is that applicationSettings is actually a section group not a section.  I know it’s a subtle difference but the ReplaceConfigSections task for Web Deployment Projects can only replace root level sections such as appSettings and connectionStrings.  See post http://forums.asp.net/1108562/ShowPost.aspx . We have updated the task so that it can now replace sections within a section group such as “system.web/authentication” and “system.net/mailSettings”. 

     

    In your case this would allow you to replace “applicationSettings/ClassLibrary1.Properties.Settings”

     

      <configSections>

        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

          <section name="ClassLibrary1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

        </sectionGroup>

      </configSections>

      <applicationSettings>

        <ClassLibrary1.Properties.Settings>

          <setting name="ClassLibrary1_localhost_Service" serializeAs="String">

            <value>http://localhost/WebService/Service.asmx</value>

          </setting>

        </ClassLibrary1.Properties.Settings>

      </applicationSettings>

     

    You should also be aware that Class Library projects are storing the dynamic URL in a very different location than Web References in a Web Site project.  If you were to add that very same WebReference directly to the Web Site project you’d get the following added to web.config

     

      <appSettings>

        <add key="localhost.Service" value="http://localhost/WebService/Service.asmx"/>

      </appSettings>

     

    This is a root level section and can be replaced by the current ReplaceConfigSections task in Web Deployment Projects.

     

    Notice that the app.config from the Class Library project actually defined a section group named applicationSettings and a section named ClassLibrary1.Properties.Settings.  When consuming a Class Library with a Web Reference into an ASP.Net web you must copy the configSections along with the applicationSettings into the web.config file.  This will allow the config system for ASP.Net to correctly parse the file and for the Web Reference proxy generated for the Class Library project to find the dynamic URL in web.config.

     

    So, even if you could replace the “applicationSettings/ClassLibrary1.Properties.Settings“ in web.config with Web Deployment projects you’d still have to manually copy the declarations into web.config every time you added a new Web Reference to your Class Library or changed the class name.

     

    The ReplaceConfigSections task in Web Deployment Projects is really useful if all you need to do is to change the URL per deployment configuration.  It sounds like what you really want to do is to merge the app.config from the Class Library into web.config so that you’re only maintaining app.config.  If that is indeed what you’re looking for then you’ll need to author a custom MSBuild task to do the merge.  I can provide more details on this if that is what you’re trying to accomplish.

     

    Hope this helps, Brad.

     

     

     

     

     

     

     

     

     

     

  • Re: Web Deployment Project questions

    11-23-2005, 2:22 PM
    • Member
      20 point Member
    • alurch
    • Member since 10-04-2004, 8:47 AM
    • Indianapolis, IN
    • Posts 4
    Thanks for your reply Brad, and I'm sorry I didn't already find the reference post that you gave me. I hate asking repeated questions, but I've also had some trouble with the forum search on this website (probably user error...).

    I am currently manually updating the web.config file with the app.config <sectionGroup> and <applicationSettings> elements, and then wanting to use the web deployment project to update those with new URLs depending on the deployment configuration--which from your post it looks like I can do (or will soon be able to do... is that functionality in the current beta preview release? -- I will test to find out).

    A custom MSBuild task sounds like an interesting thing to learn (and I will have to at some point, I'm sure), but right now as long as I have a viable working solution (which I currently do) I'm good to go. If I need to learn about msbuild tasks, I certainly won't waste your valuable time, I'll do some googling! :)

    Thanks again for your help!
Page 1 of 1 (3 items)