bat文件修改的web.config设置 [英] bat file to modify web.config setting

查看:693
本文介绍了bat文件修改的web.config设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序在Visual Studio 2013年创建我有这个appSetting在我的web.config文件:

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

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

我发布应用程序后,我运行一个BAT文件复制发布的目录,追加今天的日期为目录名,COM presses更新目录,将其上传到谷歌驱动,所以我的团队的其他成员可以访问它。

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.

我试图使用相同的bat文件修改的 cloudVersion 的设置,所以我们可以看到,当它在应用程序中发布。我有这个code:

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

它正确地复制web.config文件,替换的 cloudVersion 的变量值。然而,整个文件现已每一行编号如下:

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?

推荐答案

在任何情况下,正在寻找,这里是我做过什么:

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

这篇关于bat文件修改的web.config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆