11626

bat file to modify web.config setting

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?

Answer1:

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""%"

Recommend

  • selector not properly set the image
  • How to decode GZip stream with odata4j in Android
  • Selective jar packaging
  • How do I transform events in Flume and send them to another channel?
  • How to specify compression for custom build environment in Ember
  • PBXCp error no such file or directory
  • Python Pandas: Adding methods to class pandas.core.series.Series
  • Query a table in different ways or orderings in Cassandra
  • Copy background from one element to another using jQuery not working in firefox
  • Why won't this override of the Model.save() function in Django work?
  • SerialForms.pas(17): W1010 Method 'Create' hides virtual method of base type 'TCompon
  • How to get a list of all blobs in a repository in Git
  • Does Windows Phone 7 have a standard Edit/Add/Delete convention?
  • Forward slash in last argument causes path to directory of batch file (“%~dp0”) to change
  • How to get all use statements declared in PHP class file
  • Get the followers on a post efficient way in laravel 5.1
  • SvcUtil.exe vs Add Reference
  • How to overcome jar dependency hell when multiple modules use the same jar?
  • How to mock current date?
  • Get count of created entries for each day
  • Send emails through VB6 if no email client
  • Web.config system.webserver errors
  • Check for zero lines output from command over SSH
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • How to revert to previous XCode version?
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • Checking free space on FTP server
  • Change Inet root folder for iis 7
  • Illegal mix of collations for operation for date/time comparison
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Updated Ionic CLI but shows previous version (Windows)
  • Release, debug version and Authorization Google?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • Confusion with PayPal's monthly billing cycle
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • Hits per day in Google Big Query