locked
Web.Release.Config <clear/> not working. RRS feed

  • Question

  • User323983933 posted

    VS2019

    ASP.NET MVC project

    In my web.config I have numerous connection strings as we all work locally so every developer has their local SQL Connection strings.

    In Web.Config.Release, I have the updated production server values, preceeded by a <clear/>.

    So Web config looks like...

      <connectionStrings>
        <!-- BRYAN -->
        <add name="ORM-BRYAN" ...  />
    
        <!-- Jim -->
        <add name="ORM-JIM" ... />
    
        <!-- DEV -->
        <add name="ORM-DEV" ... />
        
          <!-- Prod -->
         <add name="ORM-PROD" ... />
    
          <!-- Currently used -->
         <add name="ORM" ... />
    
      </connectionStrings>

    So us developers just modify the web.config locally to access our local machines, and we never check in that file.

    Now the Web.Release.Config looks like this:

    	<connectionStrings>
    		<clear />
    		<add name="ORM"
    			...
    			xdt:Transform="Replace"
    			xdt:Locator="Match(name)"
    		   />
    	</connectionStrings>

    From what I can tell, the <clear/> should have wiped out ALL the Dev connection strings, and then the new one should have been added.  Yet all the unused ones still appear after a release build/publish.

    What am I missing here?  I DO NOT want all my developer's connectionstrings getting deployed on the webserver.  Neither do I want to manually edit the publish every single time.

    Thursday, May 13, 2021 7:28 PM

Answers

  • User475983607 posted

    From what I can tell, the <clear/> should have wiped out ALL the Dev connection strings, and then the new one should have been added.  Yet all the unused ones still appear after a release build/publish.

    According to the web.config transform documentation the syntax to remove nodes is...

    <configuration xmlns:xdt="...">
      <connectionStrings>
        <add xdt:Transform="RemoveAll" />
      </connectionStrings>
    </configuration>

    The <clear /> element is used when you want to clear inherited nodes in a standard web.config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2021 7:42 PM

All replies

  • User475983607 posted

    From what I can tell, the <clear/> should have wiped out ALL the Dev connection strings, and then the new one should have been added.  Yet all the unused ones still appear after a release build/publish.

    According to the web.config transform documentation the syntax to remove nodes is...

    <configuration xmlns:xdt="...">
      <connectionStrings>
        <add xdt:Transform="RemoveAll" />
      </connectionStrings>
    </configuration>

    The <clear /> element is used when you want to clear inherited nodes in a standard web.config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2021 7:42 PM
  • User323983933 posted

    Thanks, that was perfect.

    Of course my Match transform had to change to...

    	<connectionStrings>
    		<add xdt:Transform="RemoveAll" />
    		<add name="ORM"
    			connectionString="..."
    			providerName="System.Data.SqlClient"
    			xdt:Transform="Insert"
    			xdt:Locator="Match(name)"
    		   />
    	</connectionStrings>

    And not that it's a problem but all the comment lines I had stayed in the transformed web.config.

    Friday, May 14, 2021 7:42 PM
  • User475983607 posted

    And not that it's a problem but all the comment lines I had stayed in the transformed web.config.

    Write a transform to remove comments.  I believe the XPath command is //connectionStrings/comment().  You might have to play with the path.

    <add xdt:Transform="RemoveAll" xdt:Locator="XPath(//connectionStrings/comment())" />

    Friday, May 14, 2021 7:49 PM