在命令行中将ASP.Net Core应用程序发布到Azure静默失败

问题描述:

我正在尝试将dotnet核心应用发布到Azure.我创建了一个发布配置文件,并使用Visual Studio正常运行.但是,由于我想设置连续部署,因此我需要使用命令行来运行部署.

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.

官方文档在确定[ProfileName].ps1是最佳的攻击计划.

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!

如何通过Powershell使Azure部署工作正常?

How can I make the Azure depoyment via Powershell work?

在通过publish-module.psm1进行调试以弄清为什么未部署任何东西之后,我注意到需要提供更多参数的命令.这是这样的:

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'}

您显然必须替换%PublishProfile.Username%%PublishProfile.Password%,并可能修改Production-publishProduction.pubxml

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

请注意,仅需要Password参数(考虑到您的.pubxml文件中提供了UserName)

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

我实际上最终写了一篇关于如何使用TeamCity编译和部署asp.net核心站点的博客文章: 如何使用Teamcity将ASP.NET Core站点部署到Azure/IIS…或仅通过命令行

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