Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

msbuild to publish different publishing profile

Roman Baranov March 10, 2015

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

1 vote
Nona Drake March 13, 2017

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/

 

0 votes
Roberto20 January 4, 2017

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>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events