Is it possible to modify the web.config of an existing site using MSDeploy?

Is it possible to change (or just replace) the web.config of an existing site using MSDeploy?

+4
source share
2 answers

You can replace some sections (specified by xPath or regular expression) of the web configuration file. Use the -declareParam en -setParam command line switches for this.

In this way

msdeploy -verb:sync -source:apphostconfig="Default Web Site" -dest:package=ParameterPackage.zip -declareParam:name=param,kind=XmlFile,scope=web.config,match=//add/@value 

or so:

 msdeploy -verb:sync -source:package=ParameterPackage.zip -dest:auto -setParam:name=param,value=MyDefaultWebPage.htm 

You can find more information here if you use the command line.

If you are working with importing and exporting packages to and from IIS, you can create the parameters.xml file. Vishal Joshi We have a lot of good reports about how to use msdeploy (eg the this )

+4
source

Yes you can do it. I just posted a blog on this http://sedodream.com/2012/02/14/HowToUpdateASingleFileUsingWebDeployMSDeploy.aspx , but I also copy the content below for you.

The other day I saw a question that was posted on StackOverflow asking if it is possible to update web.config using MSDeploy. I actually used a technique where I updated one file in one of my previous posts in How to disable your web application at the time of publication , but it was not called too much. In any case, I will show you how you can update a single file (in this case web.config) using MSDeploy.

You can use the contentPath provider to facilitate updating a single file. With contentPath, you can sync a single file or an entire folder. You can also use the IIS application paths to resolve where the file / folder is located. For example, if I have a web.config file in a local folder named "C: \ Data \ Personal \ My Repo \ sayed-samples \ UpdateWebConfig" and I want to update my IIS website UpdateWebCfg running on the default website in My folder I would use the command shown below.

 %msdeploy% -verb:sync -source:contentPath="C:\Data\Personal\My Repo\sayed-samples\UpdateWebConfig\web.config" -dest:contentPath="Default Web Site/UpdateWebCfg/web.config" 

From the command above, you can see that I set the path to the source content to the local file and the path to the final content using the IIS path {SiteName} / {AppName} / {file-path}. In this case, I update the site running in IIS on my local machine. To update the one that is running on the remote computer, you will need to add the computer_name and possibly some other values ​​to the -dest argument.

You can view the latest sources of this example in my github repo .

+3
source

Source: https://habr.com/ru/post/1390226/


All Articles