msbuild to publish different publishing profile

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

2 answers

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

<appSettings>
.. some keys... 
<add key="env" value="ENV" />
<add key="email" value="emailaddress@env.com"/>
<add key="url" value="env.domain.com"/>
.. more keys...
</appSettings>

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

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

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

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

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/

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

428 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you