I'm trying to automate the publishing of a .Net Core app on the Mac/Linux command line using the "dotnet" tool. No command I've tried has resulted in the project getting published to the folder the publish profile specifies. The publish profile works when I use Visual Studio for Mac to directly publish the project. I've tried many variations of both the dotnet publish -p:PublishProfile=... command and also dotnet build -p:DeployOnBuild=True -p:PublishProfile=.... It looks like it's silently ignoring the PublishProfile I give it, and indeed the output doesn't look materially different if I give it an intentionally bad path.
I've tried specifying the csproj and not, pwd in the solution directory and in the project directory, and nothing seems to work except using Visual Studio instead of the dotnet CLI.
I'm running on a Mac running 10.15.5, and CentOS 7, both with dotnet 3.1.301.
My publish profile is the default folder publishing profile, named Properties/PublishProfiles/DockerImage.pubxml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>AnyCPU</LastUsedPlatform>
<publishUrl>docker-image</publishUrl>
<DeleteExistingFiles>true</DeleteExistingFiles>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
</PropertyGroup>
</Project>
I see this output, indicating the app was published to the default directory instead of the docker-image folder I specified:
> dotnet publish -p:PublishProfile=ProjectName/Properties/PublishProfiles/DockerImage.pubxml
Determining projects to restore...
All projects are up-to-date for restore.
ProjectName -> /Users/dfrankel/Projects/Solution Name/ProjectName/bin/Debug/netcoreapp3.1/ProjectName.dll
ProjectName -> /Users/dfrankel/Projects/Solution Name/ProjectName/bin/Debug/netcoreapp3.1/publish/
Any help would be appreciated (including whether I may have posted this on the wrong project – I thought it was the right one when I posted). I'm totally stuck and can't find anything I'm doing wrong.
@abbeycode thanks for contacting us.
We'll route this to the right people and we'll come back to you.
@vijayrkn can you take a look at this?
@abbeycode can you pass /bl in the command line and please share the binlog(https://github.com/KirillOsenkov/MSBuildStructuredLog)?
@wli3 This issue should be in the sdk repo. The code that deals with publish is in websdk.
@vijayrkn I've attached the binlog. Thanks for taking a look!
@vijayrkn @javiercn @wli3 Please let me know if there's anything else I can provide to help resolve this.
@abbeycode - I will take a look today and get back before the end of day.
@abbeycode - I looked at the binlog but the publish profile is not imported

If you pass in the publish profile name, it should get imported here - https://github.com/dotnet/sdk/blob/f98197d56b051f8c5078e9017de1ef7046125205/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.ImportPublishProfile.targets#L19
Can you share the whole project & the exact command that you ran?
Ideally you will only have to run this:
dotnet build -p:DeployOnBuild=True -p:PublishProfile=DockerImage
I ran this command, though I also tried the one you gave with the same results (dotnet build OneDriveConnector -p:DeployOnBuild=True -p:PublishProfile=FolderProfile):
dotnet publish OneDriveConnector -p:PublishProfile=OneDriveConnector/Properties/PublishProfiles/FolderProfile.pubxml
I've attached the project, as it currently stands. I have also tried both commands without specifying the project name.
The name of your profile is docker-image.
So the command should be
dotnet publish -p:PublishProfile=docker-image
Apologies, I've been trying so many permutations of naming and commands I forgot where I had left off. When I call dotnet publish -p:PublishProfile=docker-image or dotnet build -p:DeployOnBuild=True -p:PublishProfile=docker-image, I still get the same result.
I tried your sample. Here is what is needed:
Change the profile to this. Replace the contents of the file in Properties\PublishProfiles\docker-image.pubxml
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>../docker-image</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
</PropertyGroup>
</Project>
Then run the command:
dotnet publish /p:PublishProfile=docker-image
This should work.
you were using a version of the profile for web. you need websdk for the profile you provided. Since your project file only has NetSdk, this should work.
Thanks, that worked now! I had that publish profile because Visual Studio 2019 for Mac generated it, though, and it works fine from within Visual Studio. It seems like it should work in both places or in neither, right? Visual Studio doesn't work for the new publish profile now, either:

I will have to see how VS Mac is using this profile. Adding some additional properties might fix this. I will take a look.
Fwiw, I'm seeing the same issue using VS 2019 16.7.2 on Windows 10 with a .net core 3.1 console app using a VS2019 generated stock FileProfile. No combination of command line dotnet build or dotnet publish will honor the FolderProfile set up for the main console application project in the solution.
To make it even crazier, if you run VS -> Tools -> Command Line -> Developer Command Prompt to open a command session and then run dotnet publish you'll get published to a pubTmp folder instead, so there's something happening in the tools environment between the cli and ide.
Fwiw, I'm seeing the same issue using VS 2019 16.7.2 on Windows 10 with a .net core 3.1 console app using a VS2019 generated stock FileProfile. No combination of command line dotnet build or dotnet publish will honor the FolderProfile set up for the main console application project in the solution.
To make it even crazier, if you run VS -> Tools -> Command Line -> Developer Command Prompt to open a command session and then run dotnet publish you'll get published to a pubTmp folder instead, so there's something happening in the tools environment between the cli and ide.
After applying the change recommended by Vijay, ie to change the contents of the default FolderProfile created by the VS Publishing Wizard, I was able to get command line dotnet publish to recognize the publishing profile.
I noticed as well that the publish profile is ignored when using _dotnet publish_. It doesnt occure if you use build and set -p:DeployOnBuild=True but I build the project in my pipeline before this is clearly missing if it doesnt work with publish.
I'm experiencing the same bug with _dotnet publish_ using the PublishProfile. The following works and gets published to _bin\Release\PublishOutput_ folder:
dotnet build /p:DeployOnBuild=True /p:Configuration=Release /p:PublishProfile=FranksFolderProfile
However, using _publish_ with the same profile ignores the publishUrl field in the profile:
dotnet publish /p:Configuration=Release /p:PublishProfile=FranksFolderProfile
This ends up in the folder _bin\Release\netcoreapp3.1\win7-x64\publish_
Here's what my pubxml file looks like:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<ProjectGuid>40aa877f-1206-408a-8d96-ab1f8f84e75b</ProjectGuid>
<publishUrl>bin\Release\PublishOutput</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<SelfContained>true</SelfContained>
<_IsPortable>true</_IsPortable>
<PublishReadyToRun>True</PublishReadyToRun>
</PropertyGroup>
</Project>
I am encountering the same kind of problem.
The profile, named win-x86:
<?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>ReleaseCore</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\PublishDir\win-x86\CoreApp\Plugins\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>
The command line:
dotnet publish -p:PublishProfile=win-x86 -f netcoreapp3.1
result:
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 pour .NET
Copyright (C) Microsoft Corporation. Tous droits réservés.
Identification des projets à restaurer...
Tous les projets sont à jour pour la restauration.
CoreLib -> C:\Users\dt\source\repos\TestBuild\CoreLib\bin\Debug\netcoreapp3.1\CoreLib.dll
Plugin1 -> C:\Users\dt\source\repos\TestBuild\Plugins\Plugin1\bin\Debug\netcoreapp3.1\Plugin1.dll
Plugin1 -> C:\Users\dt\source\repos\TestBuild\Plugins\Plugin1\bin\Debug\netcoreapp3.1\publish\
Plugin1 should be deployed to ....\PublishDir\win-x86CoreApp\Plugins, but it is not.
Please note I have just installed sdk 5-RC2 & Visual Studio Preview, I do not know if this issue is linked to that:
dotnet --info
SDK .NET Core (reflétant tous les global.json) :
Version: 3.1.403
Commit: 9e895200cd
Environnement d'exécution :
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.403\
Host (useful for support):
Version: 5.0.0-rc.2.20475.5
Commit: c5a3f49c88
.NET SDKs installed:
3.1.403 [C:\Program Files\dotnet\sdk]
5.0.100-rc.2.20479.15 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-rc.2.20475.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-rc.2.20475.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-rc.2.20475.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download