46

I'm trying to call "dotnet publish" with a specific publish profile pubxml file as documented here :

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.1&tabs=aspnetcore2x

However, everything I try seems to result in the default behaviour, and the /p:PublishProfile part is ignored.

dotnet publish /p:PublishProfile="MyFolderProfile"

Doesn't work, and logs no error, building to the default location under "/obj".

I do note that an intentionally incorrect command has the same result though, eg:

dotnet publish /p:PublishProfile="MyFolderProfile-XXXXX"

What am I doing wrong? - Any pointers would be greatly appreciated!

Lanorkin
  • 7,050
  • 2
  • 38
  • 58
Sam
  • 1,068
  • 1
  • 8
  • 15
  • Of course, it's not a solution, but I ended up listing all options (Release, output directory, etc.) manually – Felix May 26 '18 at 20:39
  • Have you tried specifying the project the profile was built upon? Like this: `dotnet publish WebApplication.csproj /p:PublishProfile="MyFolderProfile"` – Victor Alves Aug 01 '18 at 15:56
  • 3
    @VictorAlves I'm not the original poster, but I have tried with the project in the command line and that doesn't help either. It seems the problem is a long existing one, even using msbuild: https://github.com/Microsoft/msbuild/issues/1901 It seems you will have to manually specify the parameters on the command line, e.g. `-c Release`, `/p:PublishDir=dist`, etc – Falconne Aug 22 '18 at 05:08
  • 3
    I only ever run into these issues with microsoft software. – aaaaaa Feb 06 '19 at 09:14
  • 1
    See my answer: https://stackoverflow.com/a/62954314/73573 – palindrom Jul 17 '20 at 12:57

7 Answers7

18

My response is late. My solution has a simple .NET Core console application ConsoleAppCore.csproj. I used Visual Studio IDE to generate a publish profile with the name FolderProfile.pubxml and then the following commands worked for me:

Relative path - From the solution root

dotnet publish ConsoleAppCore\ConsoleAppCore.csproj /p:PublishProfile=ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml

Absolute path - From any location

dotnet publish "C:\work\ConsoleAppCore\ConsoleAppCore.csproj"   "/p:PublishProfile=C:\work\ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml"

On Azure dev ops

Task name=.NET Core

Task version=2

Command=publish

Path to projects=I left this empty

Arguments=

$(System.DefaultWorkingDirectory)\ConsoleAppCore\ConsoleAppCore.csproj /p:PublishProfile=$(System.DefaultWorkingDirectory)\ConsoleAppCore\Properties\PublishProfiles\FolderProfile.pubxml  --configuration $(BuildConfiguration) --output  $(Build.ArtifactStagingDirectory)\ConsoleAppCore-Publish\

In the Azure Dev Ops build pipeline scenario, I have redirected the output to a folder under $(Build.ArtifactStagingDirectory) . I also have a Publish Artifact task which is configured to use the staging directory variable.

I have made use of the publish profile XML file because I wanted a single file to govern the complete behavior while on Azure Devops. Relying on a single file for all parameters simplifies management on Azure.

Azure Dev ops - Artifacts Explorer

The Publish Artifact task created a drop for me and this is how it looks. Please notice that the file name in the explorer tallies with the name specified along with the --output option in the dotnet publish task enter image description here

Sau001
  • 1,158
  • 14
  • 22
  • 1
    Unfortunately this does not seem to work the same way on linux. The publish profile is simply ignored. – Ivaylo Slavov Nov 25 '19 at 15:39
  • I can't speak for Linux but this is the most surefire way to get it to wok on Windows. – Taul Jan 22 '20 at 16:38
  • The "Relative path - From the solution root" solution worked for me! Thanks – Jan Mar 17 '21 at 08:02
  • 1
    Looks like full / relative paths should not be working now, as per https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish "If you specify a path and file extension when setting the `PublishProfile` property, they are ignored. MSBuild by default looks in the _Properties/PublishProfiles_ folder and assumes the _pubxml_ file extension. To specify the path and filename including extension, set the `PublishProfileFullPath` property instead of the `PublishProfile` property." – Lanorkin Oct 26 '21 at 13:11
14

I ran into the same issue a while ago. I managed to fix it by instead calling:

dotnet build [projectname] /p:PublishProfile=[PublishProfile]
A. Don
  • 181
  • 1
  • 6
  • 1
    What will `[projectname]` be? – Anders Lindén May 06 '19 at 14:55
  • 5
    Add `/p:DeployOnBuild=true` to deploy after build - see here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.1#publish-profiles – shlgug Dec 16 '19 at 15:09
9

You might need the full path, e.g.

dotnet publish -c Release /p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml
andrewb
  • 5,069
  • 6
  • 35
  • 52
8

There is an open (as of Oct 2021) issue for Folder Publish with the similar symptoms https://github.com/dotnet/sdk/issues/12490

Workaround I use for now is to manually edit *.pubxml file produced by VS.Net to have both PublishUrl and PublishDir keys with the same values.

With this dotnet publish -p:PublishProfile=... works as expected.

Lanorkin
  • 7,050
  • 2
  • 38
  • 58
4

Try this based on: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.1#publish-profiles

dotnet build ..\project\project.csproj /p:DeployOnBuild=true -c Release /p:PublishProfile="Folder Staging"

I included a relative csproj path and a publish profile name with a space in it to clarify how to deal with those cases. The -c flag is optionally used to specify the configuration to use.

shlgug
  • 1,192
  • 2
  • 10
  • 12
1

See https://github.com/dotnet/docs/issues/19677. The PublishProfile is only the name, any directory before it is disregarded.

PublishProfile property is treated as a file name and the directory is constructed separately.

The PublishProfileFullPath property should be used if specifying a custom path.

James Esh
  • 2,072
  • 1
  • 25
  • 40
0

I used this on VS build events

dotnet publish $(SolutionDir)DIRECTORI_1/PROJECT_1.csproj -c Release -o C:\Deployments\FOLDER_1
Suraj Rao
  • 28,850
  • 10
  • 94
  • 99