Ashkan Sirous Ashkan Sirous - 8 months ago 56
C# Question

Publish Azure Application with MS-Build on vs2015

I am trying to publish my application (mvc and webapi2) using visual studio on Azure App Services. Everything working fine when I publish the normal structure.

Then I tried to add a folder that is not a part of my solution (generates and changes by front-enders some how) so I've added the required folder to msbuild and everything works fine when I publish to a normal profile (local folder).

On the next step, I try to publish the project on the azure, where I saw that it won't publish files that I've added to ms-build. How to fix it?

I've googled it and I've found this: Publish Azure Application with MSBuild and the answer is to publish using Power shell.

But the link is 2 years old and I Azure matured a lot in this 2 years. Is there any way to do it using visual studio?

please note that this is not a duplicate of Publish Azure Application with MSBuild since it is 2 years later, and on vs 2015 and Azure sdk is 2.9 not 2.2.

And if you don't agree, or anything please comment.

Answer Source

Yes, we can do it using Visual Studio. Please have a try to add following code in the project file .I create a demo for it, the following is my detail steps.

    <Content Include="C:\test\**">
  1. Create MVC project vis visual studio

  2. Unload the project from the solution via right click the project name.

enter image description here

  1. Edit the project file

enter image description here

  1. Add the script in the project file and reload the project.

enter image description here Source Files: enter image description here

  1. Publish the project to azure and check the files from the kudu tools.

enter image description here

Update: Use target to do that

<Target Name="CopyFiles" BeforeTargets="PrepareForBuild">
    <Copy SourceFiles="@(MySourceFiles)" DestinationFiles="@(MySourceFiles->'C:\Tom\MSBuild\MSBuild\test\%(RecursiveDir)%(Filename)%(Extension)')" />
  <Target Name="BeforeBuild">
      <Content Include="test\**\*.*" />