bat file to modify web.config setting

davids

I have a web application created in Visual Studio 2013. I have this appSetting in my Web.Config file:

<add key="cloudVersion" value="@@NEW@@"/>

After I publish the application, I run a bat file that copies the published directory, appends today's date to the directory name, compresses the updated directory, and uploads it to Google drive so the rest of my team can access it.

I am attempting to use the same bat file to modify the cloudVersion setting so we can see when it was published from within the application. I have this code:

@echo off &setlocal
set "search=@@NEW@@"
set "replace=%yy%%mm%%dd%"
(for /f "delims=" %%i in ('findstr /n "^" "%""C:\original files\Web.config""%"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"
type "%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"

It correctly copies the Web.Config file and replaces the cloudVersion variable value. However, the whole file now has each line numbered like this:

23:  </system.web.extensions>
24:  <appSettings>
25:    <add key="cloudVersion" value="20140818"/>

How do I use the bat to update the value, but not get numbered lines that I have to later delete?

davids

In case anyone is looking, here is what I did:

@echo off &setlocal
set "search=@@NEW@@"
set "replace=%yy%%mm%%dd%"
(for /f "delims=" %%i in ('findstr "^" "%""C:\original files\Web.config""%"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"
type "%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

bat file to modify web.config setting

From Dev

SharePoint 2010 modify web.config file with http handlers

From Dev

How to modify a key in web.config file through the code?

From Dev

Setting MIME type of a file from web.config

From Dev

Modify keyboard config file

From Dev

modify KMail config file

From Dev

Modify keyboard config file

From Dev

Modify git config file globally

From Dev

Modify config file during release

From Dev

Setting environment variables in Jenkins with a bat file?

From Dev

Setting classpath from bat file doesnt work

From Dev

getting setting from web.config in sitecore

From Dev

MSDeploy - Add new web config setting in setParams

From Dev

Display web.config setting as HTML

From Dev

How do I modify config file at runtime

From Dev

Setting an environment variable in a NuGet.Config file

From Dev

compile time config file parsing and setting parameters

From Dev

Setting a directory and adding other folders inside of that directory(.bat file)

From Dev

Issue with setting environment variable through bat file to execute a java program

From Dev

Setting the subdomain as a variable in apache config to be used in the same config file:

From Dev

Encrypt the web.config file

From Dev

web.config file transformations

From Dev

Modify appSettings in the custom config file which is referenced via 'file' attribute

From Dev

Deny all files in a directory, via web.config setting

From Dev

Setting different time zone in IIS or web.config

From Dev

Get Mail Setting from Web.Config in SendAsync Method?

From Dev

Use a Chef recipe to modify a single line in a config file

From Dev

Modify the file 'config.inc.php' for XAMPP, PHPMyAdmin & MySQL setup

From Dev

API to modify the machine.config file - 'DbProviderFactories' section can only appear once per config file

Related Related

  1. 1

    bat file to modify web.config setting

  2. 2

    SharePoint 2010 modify web.config file with http handlers

  3. 3

    How to modify a key in web.config file through the code?

  4. 4

    Setting MIME type of a file from web.config

  5. 5

    Modify keyboard config file

  6. 6

    modify KMail config file

  7. 7

    Modify keyboard config file

  8. 8

    Modify git config file globally

  9. 9

    Modify config file during release

  10. 10

    Setting environment variables in Jenkins with a bat file?

  11. 11

    Setting classpath from bat file doesnt work

  12. 12

    getting setting from web.config in sitecore

  13. 13

    MSDeploy - Add new web config setting in setParams

  14. 14

    Display web.config setting as HTML

  15. 15

    How do I modify config file at runtime

  16. 16

    Setting an environment variable in a NuGet.Config file

  17. 17

    compile time config file parsing and setting parameters

  18. 18

    Setting a directory and adding other folders inside of that directory(.bat file)

  19. 19

    Issue with setting environment variable through bat file to execute a java program

  20. 20

    Setting the subdomain as a variable in apache config to be used in the same config file:

  21. 21

    Encrypt the web.config file

  22. 22

    web.config file transformations

  23. 23

    Modify appSettings in the custom config file which is referenced via 'file' attribute

  24. 24

    Deny all files in a directory, via web.config setting

  25. 25

    Setting different time zone in IIS or web.config

  26. 26

    Get Mail Setting from Web.Config in SendAsync Method?

  27. 27

    Use a Chef recipe to modify a single line in a config file

  28. 28

    Modify the file 'config.inc.php' for XAMPP, PHPMyAdmin & MySQL setup

  29. 29

    API to modify the machine.config file - 'DbProviderFactories' section can only appear once per config file

HotTag

Archive