0

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).

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

  1. Open the .csproj file with text editor.
  2. 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:

enter image description here

3 Comments

Thanks, looks like a neat way - will give this a go.
@JamesHarcourt Have you resolved the issue by the workaround? Does it work for you?
It didn't work but after making some modifications it did work, I'll upvote as you set me on the right path but I'll post the final answer when I get a bit of time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.