Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to publish on command line using publish profile #12490

Open
abbeycode opened this issue Jun 19, 2020 · 59 comments
Open

Unable to publish on command line using publish profile #12490

abbeycode opened this issue Jun 19, 2020 · 59 comments

Comments

@abbeycode
Copy link

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/
@abbeycode
Copy link
Author

abbeycode commented Jun 23, 2020

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.

@wli3 wli3 transferred this issue from dotnet/sdk Jun 26, 2020
@javiercn
Copy link
Member

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

@vijayrkn
Copy link
Contributor

@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.

@javiercn javiercn transferred this issue from dotnet/aspnetcore Jun 26, 2020
@abbeycode
Copy link
Author

@vijayrkn I've attached the binlog. Thanks for taking a look!

@abbeycode
Copy link
Author

@vijayrkn @javiercn @wli3 Please let me know if there's anything else I can provide to help resolve this.

@vijayrkn
Copy link
Contributor

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

@vijayrkn vijayrkn assigned vijayrkn and unassigned wli3 Jun 30, 2020
@vijayrkn
Copy link
Contributor

@abbeycode - I looked at the binlog but the publish profile is not imported

image

If you pass in the publish profile name, it should get imported here -

<PublishProfileName Condition="'$(PublishProfileName)' == '' and '$(PublishProfile)' != ''">$([System.IO.Path]::GetFileNameWithoutExtension($(PublishProfile)))</PublishProfileName>

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

@abbeycode
Copy link
Author

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.

OneDrive Connector.zip

Updated binlog from the dotnet build OneDriveConnector -p:DeployOnBuild=True -p:PublishProfile=FolderProfile command

@vijayrkn
Copy link
Contributor

The name of your profile is docker-image.

So the command should be

dotnet publish -p:PublishProfile=docker-image

@abbeycode
Copy link
Author

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.

msbuild.binlog.zip

@vijayrkn
Copy link
Contributor

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.

@vijayrkn
Copy link
Contributor

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.

@abbeycode
Copy link
Author

abbeycode commented Jun 30, 2020

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:

Screen Shot 2020-06-30 at 10 05 25 AM

@vijayrkn
Copy link
Contributor

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

@vijayrkn vijayrkn transferred this issue from dotnet/websdk Jul 15, 2020
@southrivertech
Copy link

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.

@southrivertech
Copy link

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.

@mcflux
Copy link

mcflux commented Sep 21, 2020

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.

@falvarez1
Copy link

falvarez1 commented Sep 30, 2020

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>

@denis-troller
Copy link

denis-troller commented Oct 22, 2020

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

@ThorstenReichert
Copy link

Similar issue here. The dotnet commands are ignoring the publishUrl field in the .pubxml. In my case, neither dotnet publish nor dotnet build /p:DeployOnBuild=True /p:PublishProfile=FolderProfile publish to the correct folder:

  • dotnet build /p:DeployOnBuild=True /p:PublishProfile=FolderProfile publishes to <project-dir>/obj/Release/netcoreapp3.1/PubTmp/Out
  • dotnet publish publishes to <debug-output-dir>/publish (ignoring even the 'Release' configuration, it seems)

My current Properties/PublishProfiles/FolderProfile.pubxml is as follows (and works when publishing from Visual Studio):

<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>False</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <ProjectGuid>1f17a7a7-231d-4a50-9e05-35b5963f6e45</ProjectGuid>
    <publishUrl>..\..\BuildOutput\Publish\API\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <SelfContained>false</SelfContained>
    <_IsPortable>true</_IsPortable>
  </PropertyGroup>
</Project>

I have tried the .pubxml suggested by @vijayrkn as well, which works with dotnet publish. However, since my project is actually an ASP.NET Core project (using Microsoft.NET.Sdk.Web), Visual Studio refuses to publish with the same .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>

Some dotnet info:

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.102
 Commit:    71365b4d42

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support):
  Version: 5.0.2
  Commit:  cb5f173b96

.NET SDKs installed:
  5.0.100-rc.2.20479.15 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.102 [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.24 [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.24 [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.11 [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.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [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.24 [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.11 [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.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [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.11 [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]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@Miiite
Copy link

Miiite commented Mar 5, 2021

I'm also seeing this behavior.
I created a .pubxml file using Visual Studio 2019, by importing a .PublishSettings file downloaded from my azure resource.

Once the file is generated:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FTP</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://blablabla.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>d26c8b50-b10b-4413-a0d1-490620379f51</ProjectGuid>
    <publishUrl>ftp://blablabla.azurewebsites.windows.net</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <FtpPassiveMode>True</FtpPassiveMode>
    <FtpSitePath>site/wwwroot</FtpSitePath>
    <UserName>ssblazor\$ssblazor</UserName>
    <Password>XXXXXX</Password>
  </PropertyGroup>
</Project>

I tried using it from the dotnet CLI (on my Mac) with:

dotnet publish -c Release /p:PublishProfile=Properties/PublishProfiles/azure.pubxml
or with
dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=Properties/PublishProfiles/azure.pubxml

and in both cases here is the output I'm getting:

Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  BlazorSSBDemo -> /Users/adrienpadol/Git/BlazorSSBDemo/bin/Release/net5.0/BlazorSSBDemo.dll
  BlazorSSBDemo -> /Users/adrienpadol/Git/BlazorSSBDemo/bin/Release/net5.0/BlazorSSBDemo.Views.dll
  BlazorSSBDemo -> /Users/adrienpadol/Git/BlazorSSBDemo/obj/Release/net5.0/PubTmp/Out/

So the build is done, but the publication step is never executed, without any feedback as to why.

I also did manage to deploy my project from my mac using the VSCode Azure extension, via the "Deploy to Web App..." option from my Azure resource explorer.
But this way of deploying the app is not using a publishProfile file, it just executes dotnet commands, with the authentication information it already has from my previous log-in operation in VSCode.

dotnet clean /Users/adrienpadol/Git/BlazorSSBDemo /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary
then
dotnet publish /Users/adrienpadol/Git/BlazorSSBDemo --configuration Release /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary

Any help would be appreciated as to why specifying a .pubxml to dotnet publish fails on a mac.

@willnationsdev
Copy link

@Miiite So, I'm having the same issue personally on my Windows machine, however, in regards to your specific case, I think part of the problem is how you are specifying the publish profile. According to the dotnet publish command docs...

The preceding example uses the FolderProfile.pubxml file that is found in the <project_folder>/Properties/PublishProfiles folder. 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.

You are providing an actual path to the PublishProfile property which is always ignored. So you're likely just doing the default process of building + the Release configuration (since you specified it). And then it stops cause it hasn't received more instructions to do anything else.

@Miiite
Copy link

Miiite commented Mar 11, 2021

@willnationsdev I totally missed that part of the dotnet publish spec, you're right. But TBH I had started my tests with the proper syntax dotnet publish --configuration Release /p:PublishProfile=azure before switching to specifying the full path of the file, and even with that syntax the output is still the same.
Thanks for the feedback though.

@vijayrkn
Copy link
Contributor

vijayrkn commented Nov 1, 2021

@mcflux - Yes, agreed. That's why we have created this item #20931. Once this fixed, you won't have to set both properties. Only one of them should be enough.

@mcflux
Copy link

mcflux commented Nov 1, 2021

@vijayrkn ah okay. Excellent 👌

@lanorkin
Copy link

lanorkin commented Nov 2, 2021

@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

@hallambaker
Copy link

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.

@hallambaker
Copy link

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

Publish from inside VS 2022 works fine.

Release x64 ..\..\Outputs\win-x64 FileSystem net6.0-windows win-x64 true True True True

========== 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.

@warmfire540
Copy link

warmfire540 commented Mar 31, 2022

confirming that @lanorkin 's workaround works... manually adding PublishDir which is a duplicate of PublishUrl allows dotnet publish to work from CLI (for CI/CD purposes)

update
can confirm also that DeleteExistingFiles is indeed ignored.. so had to add some manual CI logic to clean the directories to work around me wanting to use the publish profiles for ease

@theCuriousOne
Copy link

for me the dotnet publish was not working (not publishing anything to designated folder), because I had the old style of .csproj (.net framework style - before the simplified SDK style)

@tomkerkhove
Copy link
Member

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.

@jsrraman
Copy link

jsrraman commented Jan 4, 2023

@wolfding @mcflux @imjustalf @guidomocha - This issue once fixed should address most of the above 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.

This works for me.

@A9G-Data-Droid
Copy link

A9G-Data-Droid commented Sep 26, 2024

This is one of those things that seems like it should be easy and it's not. There are so many overlapping functionalities and syntax. It's quite the minefield.

Over 4 years later new people are still showing up here with the same problem. Still, nobody from Microsoft has told us what commands are run when the Publish button in the Visual Studio GUI is pressed. Is it even reproducible outside of the GUI?

@baronfel
Copy link
Member

In general VS is orchestrating a multi-stage operation, whereas dotnet is just running the Publish target.

In VS, when you publish with a publish profile that profile is read and the properties in it are applied before the Publish target is run. This does not happen at the CLI (I have a very old PR we could possibly revive) and is one reason why behaviors differ.

In addition, many of the behaviors and publish profiles that are supported in VS simply have no matching SDK or cross platform implementation - they were expressly designed to be run from within the context of a VS IDE experience and so cannot be run from the CLI.

@hallambaker
Copy link

Ahh, that would explain things, there is a slot in the CLI to specify the publishing profile but if that profile is then ignored, that would explain it...

I guess what I need to do is probably create a tool that creates a script that does the necessary...

@baronfel
Copy link
Member

The confusing thing about Publish Profiles at the CLI is that they actually do something - they are like little property bags that get applied to your build.

The problem is twofold:

  • they often set properties that have already been used/set earlier in the build, so their property changes either have no effect or have a mixed impact, and
  • they often set a PublishProtocol that doesn't exist or doesn't work on the CLI, and we've chosen a 'fail silently' approach to this on the CLI to not break people. This is potentially something the SDK could make an opt-in warning via a BuildCheck in the future though.

@A9G-Data-Droid
Copy link

Thanks @baronfel, this is all good information. My original query still stands. I can, and do, script a multi-stage operation. What series of commands can replicate the publish operation that VS does?

@baronfel
Copy link
Member

baronfel commented Sep 27, 2024

Without knowing more about what kind of publish you are triggering from VS it's impossible to tell. What specifically are you doing in VS that you'd like to replicate? What kinds of projects, etc? Do you have a sample?

@A9G-Data-Droid
Copy link

Right now I am attempting to automate the publishing step in a solution with multiple projects so I don't need to publish them one by one. It's a series of desktop projects with folder publish profiles that look like this:

FolderProfile.pubxml

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>Publish</PublishDir>
    <PublishUrl>Publish</PublishUrl>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net8.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <PublishReadyToRun>false</PublishReadyToRun>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

I have tried running it a few different ways and I run into various errors. When it does complete it doesn't run my after publish steps. Currently I need to add these steps to my script so they will run from either the publish button, or the script.

I was using some steps in the csproj for tracking hashes and making an installer like this:

  <!-- Create NSIS installer -->
  <Target Name="BuildInstall" AfterTargets="Publish">
    <Message Text="Running the build installer script:" Importance="High" />
    <Exec Command="Publish\BuildInstall.cmd" />
  </Target>

  <!-- Hashing artifacts for verifiable builds -->
  <ItemGroup>
    <FilesToHash Include="Publish\*" />
  </ItemGroup>
  <Target Name="GetHash" AfterTargets="Publish">
    <Message Text="Calculating hashes for all files in the publish directory: @(FilesToHash)" Importance="High" />

    <GetFileHash Files="@(FilesToHash)">
      <Output TaskParameter="Items" ItemName="FilesWithHashes" />
    </GetFileHash>
    <WriteLinesToFile File="BuildHashes.txt" Lines="@(FilesWithHashes->'%(FileHash)  %(Identity)')" Overwrite="true" />

    <Message Importance="Low" Text="@(FilesWithHashes->'%(FileHash)  %(Identity)')" />
  </Target>

@A9G-Data-Droid
Copy link

Ok, @baronfel said something about certain things not being applied during the original build step and that struck a chord. I merged the settings from the FolderProfile into each corresponding .csproj file. This way, those settings are present during my build step.

Then I ran:

dotnet.exe publish "path\to\project.csproj" /p:DeployOnBuild=true /p:PublishProfile="FolderProfile" --no-build -o "path\to\Publish"

That allowed me to follow a standard build, test, publish deployment like what would happen on the build server.

Now I'm getting what appears to be the same results from the publish button, a build script, and the GitHub action.

This defeats the whole purpose of the PublishProfile being in a separate file. If you had multiple publish profiles then this would be more complicated. There would need to be a better way to apply the publish profile so it works without having those settings added to the csproj.

Maybe I could get the same effect with the right set of switches instead of applying the settings to the csproj.

This is why people use tools like cake and nuke

@baronfel
Copy link
Member

@A9G-Data-Droid I found my old PR mimicking the VS behavior: #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.

@A9G-Data-Droid
Copy link

Thanks @baronfel ! I always enjoy seeing the internal struggles behind why things are the way they are. So where does this issue stand? Is there any movement in the sdk team to get cli\gui parity? In a world of automated deployments I would expect the VS GUI to be generating reproducible commands that will work on a headless build server.

Take it a step further, Visual Studio could create the build script and run it when you press the button. I know that's a major structural change but it would ensure that the process was identical. It would remove all the mystery from the black box. This could also align cross platform build disparity. As far as PowerShell runs on any supported platform, so too would the build. I know, easier said than done.

@baronfel baronfel self-assigned this Sep 27, 2024
@baronfel baronfel added this to the Backlog milestone Sep 27, 2024
@baronfel baronfel added the needs team triage Requires a full team discussion label Sep 27, 2024
@marcpopMSFT marcpopMSFT modified the milestones: Backlog, 10.0.1xx Oct 1, 2024
@marcpopMSFT marcpopMSFT removed the needs team triage Requires a full team discussion label Oct 1, 2024
@marcpopMSFT
Copy link
Member

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.

@jonswaino
Copy link

jonswaino commented Jan 22, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests