69

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

https://learn.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!

5
  • Of course, it's not a solution, but I ended up listing all options (Release, output directory, etc.) manually
    – Felix
    Commented May 26, 2018 at 20:39
  • Have you tried specifying the project the profile was built upon? Like this: dotnet publish WebApplication.csproj /p:PublishProfile="MyFolderProfile" Commented Aug 1, 2018 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: 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
    Commented Aug 22, 2018 at 5:08
  • 6
    I only ever run into these issues with microsoft software.
    – aaaaaa
    Commented Feb 6, 2019 at 9:14
  • 1
    See my answer: stackoverflow.com/a/62954314/73573
    – palindrom
    Commented Jul 17, 2020 at 12:57

8 Answers 8

27

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

5
  • 2
    Unfortunately this does not seem to work the same way on linux. The publish profile is simply ignored.
    – stackh34p
    Commented Nov 25, 2019 at 15:39
  • I can't speak for Linux but this is the most surefire way to get it to wok on Windows.
    – Taul
    Commented Jan 22, 2020 at 16:38
  • The "Relative path - From the solution root" solution worked for me! Thanks
    – Jan
    Commented Mar 17, 2021 at 8:02
  • 5
    Looks like full / relative paths should not be working now, as per learn.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
    Commented Oct 26, 2021 at 13:11
  • Agree with @lanorkin - PublishProfileFullPath is preferred. Running from within a .bat I used %~dp0 (see here) to help convert relative paths into absolute paths suitable for use with PublishProfileFullPath parameter.
    – prairiehat
    Commented Jun 7 at 10:22
17

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

dotnet build [projectname] /p:PublishProfile=[PublishProfile]
2
13

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.

2
  • 2
    This was the fix for me. Thanks!
    – solrevdev
    Commented Feb 21, 2022 at 13:25
  • 3
    Note that as mentioned in the thread, this still ignores things like 'DeleteExistingFiles'
    – Rotem
    Commented May 31, 2022 at 17:55
11

You might need the full path, e.g.

dotnet publish -c Release /p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml
2
  • Without specifying either sln or csproj file? Commented May 6, 2019 at 14:56
  • @AndersLindén yep I didn't need to specify that, but I probably just had a single .csproj file in the directory
    – andrewb
    Commented May 8, 2019 at 5:40
4

Try this based on: https://learn.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.

3

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.

3

To solve the problem you must add a < PublishDir > property to your .pubxml file. Then the

dotnet publish /p:Configuration=Release /p:PublishProfile=FolderProfile

command works fine.

Example below.

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <DeleteExistingFiles>false</DeleteExistingFiles>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>C:\MyApp\PUBLISH</PublishUrl>
    <PublishDir>C:\MyApp\PUBLISH</PublishDir>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <_TargetId>Folder</_TargetId>
  </PropertyGroup>
</Project>

you can also use a relative path like

    <PublishUrl>PUBLISH</PublishUrl>
    <PublishDir>PUBLISH</PublishDir>
1

I used this on VS build events

dotnet publish $(SolutionDir)DIRECTORI_1/PROJECT_1.csproj -c Release -o C:\Deployments\FOLDER_1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.