Search code examples
azurebuildazure-devopscommand-line-interfacepublish

How to build a web app MVC5-WEB API 2 in Azure Devops with CLI?


I want to build a web app (web api 2) in Azure but i don't want to obtain a zip, i just want to get a directory with all necessary files. I don't know the command line to do that. I don't want to use the classical deploy web app task because i need to add additional files after the build. Thanks in advance for your help.


Solution

  • How to build a web app MVC5-WEB API 2 in Azure Devops with CLI?

    You could use Visual Studio Build task with MSBuild Arguments:

    /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish 
    

    to publish web app to artifact folder or any other folder you want.

    You also can specify the publish profile directly:

    /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile="{publish profile name}";publishUrl="$(build.artifactstagingdirectory)"
    

    With FileSystem publish method, the published files are in a folder, not zipped.

    And if you want use the command line task instead of Visual Studio Build task, you could invoke MSBuild.exe with same MSBuild Arguments to build this solution/project:

    "<PathForMSBuild.exeOnYourAgent>\MSBuild.exe" "<YourProject/SolutionPath>" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
    

    enter image description here

    If you want to add additional files after the build, you could add a task after Visual Studio build task, or you can create AfterBuild Target in your project to add additional files.

    Hope this helps.