How do I configure MSBuild to use a saved publishProfile for WebDeploy?
Asked Answered
E

1

32

I have used Visual Studio to create a publish profile. It saved that information to MyProject.Publish.xml, located in the root of my project directory.

I would like the MSBuild task that gets executed on my CI server to use that file as its base settings. Ideally, if I could override properties via command line parameters, that would rock.

Is this possible? If so, what is the syntax?

For example, I'm looking for something like:

MSBuild MyProject.csproj /P:UsePublishProfile=True /P:UserName=deployUser /P:Password=MyPassword
Ellyellyn answered 3/2, 2011 at 18:42 Comment(1)
Did you ever find out how to do this?Ironmaster
A
42

I'm sorry to tell you that the publish.xml file which VS2010 uses was not designed to be used in this way. In fact it was not even designed to be checked-in/shared with others.

The logic for reading/writing those files are strictly contained inside Visual Studio and not available through MSBuild. So there is no straight forward way of doing this today. You have to pass in the individual property names/values when you call msbuild.exe. You can see a similar question that I answered at Team Build: Publish locally using MSDeploy for more info.

Note for VS 11 Developer Preview

Just so you know we have addressed this in the up coming version of Visual Studio. You can see if by downloading the VS 11 developer preview. Now all the profiles are saved into their own files (under the PublishProfiles in the Properties node in Solution Explorer). They are now designed to be checked in and shared with team members. These files are now MSBuild files and you can customize them if you wish. In order to publish from the command line just pass DeployOnBuild=true and set PublishProfile to the name of the profile. For example:

msbuild.exe MyProject.csproj /p:DeployOnBuild=true;PublishProfile=MyProfile
Aria answered 29/12, 2011 at 4:52 Comment(11)
This Visual Studio 2012 commandline does appear to work. Is there any further documentation now that it is RTM?Glasshouse
Not at this time, but I'm working on formal docs and I'll be blogging at sedodream.com in the short term till we can get those docs written up. Hit me up if you'd like to see smtg specific.Aria
How do you get it to use the EncryptedPassword so that you don't have to add a <Password> node to the profile to get it to run without command params?Glasshouse
@SayedIbrahimHashimi can this method be used through a TFS build definiton - Have a look at my question please #14091067Slaw
Hi, @Slaw I have replied there.Aria
@Glasshouse you cannot. EncryptedPassword can only be decrypted on the same machine/user as it was generated. For build server scenarios you will need to handle encryption/decryption. You would need to set the Password property from some encrypted source.Aria
I would add to this that in order for any additional web transforms to correctly work you also have to add /p:Configuration=MyConfiguration to the command line parametersStupefy
My solution has 3 web projects that go to different places and those configurations are specified in each application project file, however I want to specify a publish profile for each of them so that I can make a rule to skip certain files from being deleted. I'm guessing that by specifying 1 publish profile in TFS build definition for MSBuild it will use that same profile for all projects?Finder
@SayedIbrahimHashimi I'm trying to use a publish profile in a TFS build like Marvin asked about above in order to precompile a web application, though it doesn't seem to be triggering the publish profile. Any ideas? #27074514Weasner
@Weasner #27074514Aria
I'm using Visual studio 2015 and WCF still seems to use the old deployment method, so I guess this is not solution?Uphemia

© 2022 - 2024 — McMap. All rights reserved.