Sam7 Sam7 - 1 month ago 22
ASP.NET (C#) Question

Publishing ASP.Net Core app to Azure silently fails in command line

I'm trying to publish a dotnet core app to Azure. I've created a publish profile and using visual studio it all works fine. But since I'd like to setup continuous deployment I need to run the deployment using command line.

The official documentation was pretty helpful in identifying that the

[ProfileName].ps1
is the best plan of attack.

However it gives no clues on how to use it.
First I ran it without parameters and got this error:

Production-publish.ps1 : The term 'Production-publish.ps1' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:1
+ Production-publish.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Production-publish.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Next I added the needed parameters:

.\Production-publish -packOutput 'C:\code\my-dotnetcore-proj\publish' -pubProfilePath 'Production.pubxml'


Which ran without error but didn't do ANYTHING!

How can I make the Azure depoyment via Powershell work?

Answer

After debugging through the publish-module.psm1 to figure out why nothing was getting deployed I noticed that the command is required to supply more parameters. This is how:

.\Production-publish -packOutput 'C:\code\my-dotnetcore-proj\publish' -pubProfilePath 'Production.pubxml' -publishProperties @{
    'username' = '%PublishProfile.Username%'
    'Password' = '%PublishProfile.Password%'
    'AllowUntrustedCertificate' = false
    'AuthType' = 'Basic'}

You obviously have to replace %PublishProfile.Username% and %PublishProfile.Password% and possibly modify Production-publish and Production.pubxml

Note that only the Password parameter is required (considering that the UserName is provided in your .pubxml file)

I actually ended up writing blog article on how to compile and deploy asp.net core sites with TeamCity: How to deploy ASP.NET Core sites using Teamcity to Azure/IIS … or just command line