Reputation: 6379
I have a web application in VS 2017 for which I've defined a publish profile which works, happily, deploying / publishing the website to a location on the file system.
I understood that this was possible as part of the regular build process, i.e. just building the solution in Visual Studio or TFS build - and that this was achievable with a section like this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DeployOnBuild>True</DeployOnBuild>
<PublishProfile>ProfileName</PublishProfile>
</PropertyGroup>
However, this has no effect whatsoever, the build output log just shows the regular build happening and no attempt to publish.
Should this work as suggested in various answers on here and MSDN - and if so, what is wrong with the above?
(In case anybody is wondering, the reason for doing this is that a single solution being built by TFS cannot separately publish > 1 web application with separate publish profiles as required with the build definition MSBuildArguments setting).
Upvotes: 0
Views: 2166
Reputation: 6379
I want to credit @Andy-MSFT who posted a very close answer, but in the end there were some vital details missing and some corrections required to make it work.
First off, the working solution was:
<Target Name="Deploy" AfterTargets="Build">
<MSBuild
Condition="'$(DeployOnBuild)'!='true' And '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
Projects="$(ProjectPath)"
Targets="WebPublish"
Properties="DeployOnBuild=true;PublishProfile=FolderProfile"/>
</Target>
The WebPublish target will only work on a TFS build server if the "Web Developer Tools" of Visual Studio (2017 in my case, as per the question) are installed. Note that the "Projects" attribute had to be set with $(ProjectPath) which is also different to Andy's answer and was also needed for this to work.
Upvotes: 4
Reputation: 30362
The DeployOnBuild
property specifically was ignored when set statically in the project file. Apparently it is a special property that must be set globally on the commandline.
As a workaround, you could call MSBuild again to pass the property. See How to: Extend the Visual Studio Build Process
.csproj
file with text editor.Add below snippet at the end, then save it.
<Target Name="AfterBuild">
<MSBuild Condition="'$(DeployOnBuild)'!='true'" Projects="$(MSBuildProjectFullPath)" Properties="DeployOnBuild=true;PublishProfile=YourPublishProfile;BuildingInsideVisualStudio=False"/>
</Target>
Below threads for your reference:
Upvotes: 3