sdk: Unable to publish on command line using publish profile

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/

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 17
  • Comments: 59 (20 by maintainers)

Most upvoted comments

It still doesn’t work for me. This is broken and there are multiple issues. I keep opening issues and getting fobbed off. Told I am complaining to the wrong group.

  1. The documentation is atrocious, stop blaming developers

  2. All I want to do is to automate the publish command that I can use INSIDE Visual studio externally. I have 5 deliverables with ten platforms each I should not have to incrementally publish each one manually.

The missing command is a Visual Studio command Build -> Publish Solution -> ALL

  1. Pick one of dotnet publish / dotnet build / msbuild and stick to it.

  2. IF A PUBLISH PROFILE IS SPECIFIED IT SHOULD BE USED OR AN ERROR REPORTED

I have tried numerous variations of this command:

dotnet publish C:\Users\hallam\Work\mmm\Applications\meshhost\meshhost.csproj -c release /p:PublishProfile=publish-win-x64

They all fail in exactly the same way if I specify a non existent profile.

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>

@wolfding @mcflux @imjustalf @guidomocha - This issue once fixed should address most of the above issues. https://github.com/dotnet/sdk/issues/20931

PublishUrl is used by Visual Studio to denote the Publish target. PublishDir is used by CLI to denote the Publish target.

If you want the scenario to work in all places, You can initialize both these properties to the same values in the pubxml and the scenario will work in all places.

The reason we can’t change VS to use PublishDir is because PublishDir was created later & VS in older versions still rely on PublishUrl. So, once the default in CLI is fixed, it should take care of all issues.

If you are still running into issues, I am happy to take a look.

@vijayrkn I find something interesting. I encounter the same problem, and I changed the pubxml as your modified pubxml, it works. Compare to the VS-generated pubxml, I found the main difference is PublishUrl and PublishDir. I changed the VS-generated PublishUrl => PublishDir, everything works fine.

What’s the difference between PublishUrl and PublishDir?

<?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>

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.

Any update to this issue? I’m having the same problem as the OP. Publishing from the command line using: dotnet publish project.csprog -c Release /p:PublishProfile=TestDeploy

results in a successful build and publish to a local path but an empty path at the location specified in PublishUrl.

I’m new to using the dotnet cli, but it seems a fundamental flaw to me?

Triage: Assigned to nagilson to take a look in net10 at bringing back the prior PR on this. We won’t implement all capability of VS but we can do better than we are as there are some reasonable properties we can read and apply.

@A9G-Data-Droid I found my old PR mimicking the VS behavior: https://github.com/dotnet/sdk/pull/29817

This would eliminate the kinds of logical mismatches that you mention, however the other source of different behavior would remain: PublishProtocol types that are not available in the CLI would remain not available in the CLI.

It turns out this works for me:

$ dotnet build <path>.csproj -c Release -p:PublishProfile=LocalPublishProfile -p:DeployOnBuild=true

It did not work with publish though.

Repo is https://github.com/hallambaker/Mathematical-Mesh

Publish from inside VS 2022 works fine.

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration>Release</Configuration> <Platform>x64</Platform> <PublishDir>..\..\Outputs\win-x64</PublishDir> <PublishProtocol>FileSystem</PublishProtocol> <TargetFramework>net6.0-windows</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <SelfContained>true</SelfContained> <PublishSingleFile>True</PublishSingleFile> <PublishReadyToRun>True</PublishReadyToRun> <PublishTrimmed>True</PublishTrimmed> </PropertyGroup> </Project>

========== Build: 10 succeeded, 0 failed, 16 up-to-date, 0 skipped ========== ========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

This fails:

dotnet publish mmm.sln -c release /p:PublishProfile=publish-win-x64a

Fails with:

C:\Program Files\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CrossTargeting.targets(27,5): error NETSDK1129: The ‘Publish’ target is not supported without specifying a target framework. The current project targets multiple frameworks, you must specify the framework for the published application. [C:\Users\hallam\work\mmm\Applications\MeshReferenceLibraryClient\MeshReferenceLibraryClient.csproj]

The outputs have multiple framework targets. So the framework is specified in the .pubxml

It is not possible to specify the framework directly because only the final assemblies and the windows specific libraries specify net6.0-windows, the others specify .net6.0

dotnet publish mmm.sln -c release /p:PublishProfile=publish-win-x64a -f net6.0-windows

CSC : error CS2012: Cannot open ‘C:\Users\hallam\work\mmm\Libraries\Windows\Goedel.Cryptography.Windows\obj\Release\net6.0-windows\Goedel.Cryptography.Windows.dll’ for writing – ‘The process cannot access the file ‘C:\Users\hallam\work\mmm\Libraries\Windows\Goedel.Cryptography.Windows\obj\Release\net6.0-windows\Goedel.Cryptography.Windows.dll’ because it is being used by another process.’ [C:\Users\hallam\work\mmm\Libraries\Windows\Goedel.Cryptography.Windows\Goedel.Cryptography.Windows.csproj]

Given that this does not work, perhaps just admitting that it is broken would be the best course so folk don’t have to waste even more time on it.

Alternatively, if the Visual Studio side could have their build system report the actual command sent to the batch build app to the console, we could duplicate it.

@vijayrkn I’m afraid that “merging” PublishDir and PublishUrl will just hide actual issue (as it seems to me at least) - publishing process from visual studio and from command line are just different. For example, even if I add both PublishDir and PublishUrl into pubxml, publishing from command line using dotnet publish -p:PublishProfile=... ignores for example DeleteExistingFiles - and maybe other parameters

@willnationsdev - Let me see what I can find.

Others, please use the msbuild work-around for now, until I figure out a way to do this correctly.

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-x86\CoreApp\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

I will have to see how VS Mac is using this profile. Adding some additional properties might fix this. I will take a look.

@abbeycode - I will take a look today and get back before the end of day.