msbuild to publish different publishing profile
Asked by Roman Baranov:

Hello,

I have a website project that i did in Visual Studio 2013 and would like to use Bamboo to do CI. I created transformation packages for DEV environment, QA and Prod which basically change web.config when i build the website in Visual Studio and publish using lets say QA publishing profile. The problem is that when I try to use msbuild.exe to build and publish solution, i can't figure out how to specify which publishing profile to use, so it keeps always publishing the default dev web.config. Has anyone had similar issue and how did you resolve it?

If not, is there another approach i can take where i can have a diferent web.config be applied depending on environment?

Thank you


Answers:
author: Nona Drake
body: Hey Guys,

This question is old, but just in case someone come here, Visual Studio has the ability to have config transforms.

To tell MSBuild what publish profile to use,

/p:PublishProfile=ProfileName /p:PublishProfileRootFolder="C:\\Folder Name"

To transform your files....

<https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx>

<https://www.troyhunt.com/you-deploying-it-wrong-teamcity/>


author: Roberto20
body: I am using a just web.config file and then using the parameters.xml and profiles I am able to dynamically change the configuration for different environments.

For example I have this configuration in my web.config in order to change some of these attributes dynamically

```
&lt;appSettings&gt;.. some keys... &lt;add key="env" value="ENV" /&gt;&lt;add key="email" value="emailaddress@env.com"/&gt;&lt;add key="url" value="env.domain.com"/&gt;.. more keys...&lt;/appSettings&gt;
```

And create a parameters.xml in order to dynamically search and replace those values:

```
&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;parameters&gt;&lt;parameter name="env" description="description"&gt;&lt;parameterEntry kind="XmlFile"scope="\\web.config$"match="/configuration/appSettings/add[@key='env']/@value" /&gt;&lt;/parameter&gt;&lt;parameter name="email" description="description"&gt;&lt;parameterEntry kind="XmlFile"scope="\\web.config$"match="/configuration/appSettings/add[@key='email']/@value" /&gt;&lt;/parameter&gt;&lt;parameter name="url" description="description"&gt;&lt;parameterEntry kind="XmlFile"scope="\\web.config$"match="/configuration/appSettings/add[@key='url']/@value" /&gt;&lt;/parameter&gt;&lt;/parameters&gt;
```

then when the profiles I can create a customization for each environment:

```
&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;&lt;PropertyGroup&gt;&lt;WebPublishMethod&gt;MSDeploy&lt;/WebPublishMethod&gt;&lt;ADUsesOwinOrOpenIdConnect&gt;False&lt;/ADUsesOwinOrOpenIdConnect&gt;&lt;LastUsedBuildConfiguration&gt;Release&lt;/LastUsedBuildConfiguration&gt;&lt;LastUsedPlatform&gt;Any CPU&lt;/LastUsedPlatform&gt;&lt;SiteUrlToLaunchAfterPublish /&gt;&lt;LaunchSiteAfterPublish&gt;True&lt;/LaunchSiteAfterPublish&gt;&lt;ExcludeApp_Data&gt;False&lt;/ExcludeApp_Data&gt;&lt;MSDeployServiceURL&gt;https://ServerNameOrIpAddress/msdeploy.axd&lt;/MSDeployServiceURL&gt;&lt;DeployIisAppPath&gt;PhoenixQA&lt;/DeployIisAppPath&gt;&lt;RemoteSitePhysicalPath /&gt;&lt;SkipExtraFilesOnServer&gt;True&lt;/SkipExtraFilesOnServer&gt;&lt;MSDeployPublishMethod&gt;WMSVC&lt;/MSDeployPublishMethod&gt;&lt;EnableMSDeployBackup&gt;True&lt;/EnableMSDeployBackup&gt;&lt;UserName&gt;Administrator&lt;/UserName&gt;&lt;_SavePWD&gt;True&lt;/_SavePWD&gt;&lt;/PropertyGroup&gt;&lt;ItemGroup&gt;&lt;MSDeployParameterValue Include="env"&gt;&lt;ParameterValue&gt;dev 1&lt;/ParameterValue&gt;&lt;/MSDeployParameterValue&gt;&lt;MSDeployParameterValue Include="email"&gt;&lt;ParameterValue&gt;dev@example.com 1&lt;/ParameterValue&gt;&lt;/MSDeployParameterValue&gt;&lt;MSDeployParameterValue Include="url"&gt;&lt;ParameterValue&gt;dev.example.com 1&lt;/ParameterValue&gt;&lt;/MSDeployParameterValue&gt;&lt;/ItemGroup&gt;&lt;/Project&gt;
```