Unable to publish Azure Function v1.0 on file system as defined in publish profile using msbuild command

Viewed 159

I am trying to publish azure function v1.0 using publish profile and contents of publish profile is given below

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>C:\New folder</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net48</TargetFramework>
  </PropertyGroup>
</Project>

and this publish profile we are using with below given msbuild command (FolderProfile is the name of publish profile that we are using within command)

C:\code\msbuild "mufunctionapp.csproj" /t:Rebuild /p:Configuration=Release;PublishProfile=PublishProfiles/FolderProfile

But after running this command nothing gets copied(published) into the folder (C:\New folder) specified within publish profile. But I could see the publish artifacts ( binaries) being copied to obj\Release\net48\PubTmp\Out\bin

But If I use the same publish profile with Visual Studio 2019 ,the publish artifacts ( binaries) are getting copied into the folder specified within publish profile.

I want to publish the binaries using msbuild command with given publish profile within CI but as It is not working locally I am unable to use the msbuild there in CI pipeline.

Could you please tell me if there is anything that I am doing wrong in MSBUILD or in publish profile.

1 Answers

That's because of two reasons

  1. you may have condition set to false, Condition="false" buried deeply in your .csproject file. Try to delete just that condition, and doublecheck your $(MSBuildToolsVersion) resolves correctly to your correct VS 2019 build path and version in powershell or some CLI
  1. Now you can do the MS build, with other options but you need the two below for sure. Ref MSDN

// If running build @ **Solution level
msbuild myproject.csproj /p:DeployOnBuild=true /p:PublishProfile=myVsProfile /p:WebPublishMethod=FileSystem 

// If running build @ individual **Project level specify the correct VS version
msbuild myproject.csproj /p:DeployOnBuild=true /p:PublishProfile=myVsProfile /p:WebPublishMethod=FileSystem /p:VisualStudioVersion=17.0 
Related