如何从 powershell 执行与在 Visual Studio 中发布完全相同的功能 [英] How to do the exact same functionality as the Publish inside visual studio from powershell

查看:19
本文介绍了如何从 powershell 执行与在 Visual Studio 中发布完全相同的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何像从 Visual Studio 一样从 PowerShell 发布.

I want to know how to publish from PowerShell the same way I can from Visual Studio.

例如,当您使用 MVC 项目启动 Visual Studio 时;然后右键单击项目并选择发布";出现一个对话框,您在再次单击发布"中填写一些设置.它神奇地将您的网站按预期推出.它还创建一个文件来保存这些设置.项目名称.Publish.xml.

When you launch Visual Studio with MVC project for example; then right-click on the project and select "Publish"; a dialog box comes up that you fill out a few settings in the click Publish again. It magically pushes your website out as expected. It also creates a file to hold those settings. projectName.Publish.xml.

该文件是我希望能够以完全相同的方式使用它的原因.有一些设置可以在 powershell 中进行操作,以将应用程序推送到具有不同配置的多个站点.

That file is the reason I want to be able to use this in exactly the same manner. There are a couple of settings that could manipulated in powershell to push the application to multiple sites with differing configurations.

我查看了msbuild target:publish",它只产生(从包含 .csproj 的目录运行):

I have looked at "msbuild target:publish" which only produces (run from the directory containing the .csproj):

MSBUILD : error MSB1009: Project file does not exist.
Switch: target:publish 

我尝试过msbuild projectfile target:publish",它会产生:

I have tried "msbuild projectfile target:publish" which produces:

MSBUILD : error MSB1008: Only one project can be specified.
Switch: target:build

我还研究了几个 msdeploy 变体.不可能这么难吧!?如果您可以在工作室中右键单击,则可以执行该任务.

I've also looked at several msdeploy variations. It can't be this difficult!? If you can right-click in studio there has be something that performs that task.

我开始怀疑这是否需要满月并切掉鸡的头.(我在这上面花了很多时间!)

I'm starting to wonder if this requires a full moon and cutting the head off a chicken. (I've spent to much time on this!)

**我尝试了李的建议:

** I tried Lee's suggestion:

msbuild target:publish Mvc.csproj

产生此错误的原因:

MSBUILD : error MSB1008: Only one project can be specified.
Switch: Mvc.csproj

For switch syntax, type "MSBuild /help"

**根据 DaveE 的建议,我尝试了:

** From DaveE's suggestion, I tried:

msbuild target:publish Mvc.csproj

产生此错误的原因:

MSBUILD : error MSB1009: Project file does not exist.
Switch: target:publish=PassportHealth.PatientSimple.Mvc.csproj

我还回到了发布"目标的文档 (http://msdn.microsoft.com/en-us/library/ms165431.aspx) 这似乎很清楚,语法是:

I also went back to the documentation for the "Publish" target (http://msdn.microsoft.com/en-us/library/ms165431.aspx) which seems pretty clear that the syntax is:

msbuild target:publish

所以在重读了几遍之后,我的结论是:发布目标是一键部署.exe文件而不是MVC网站.我发现 http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx 相当清楚地说明了这个问题.我还没有看到如何通过 msdeploy 命令在其中使用publish.xml"文件.

So after rereading this several times my conclusion is this: the publish target is for one-click deployments of .exe files not MVC web sites. I have found http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx which speaks to this matter fairly clearly. I don't see how to utilized the "publish.xml" file in this via the msdeploy command yet though.

推荐答案

projectName.publish.xml 文件仅通过 Visual Studio 用于一键发布.对于 MSBuild,您需要直接在命令行上传递一堆参数 (/p:Param1=value1;Param2=value2;...).例如:

The projectName.publish.xml files are only used via Visual Studio for the One-Click publishing. For MSBuild, you need to pass a bunch of parameters directly on the commandline (/p:Param1=value1;Param2=value2;...). For example:

/p:DeployOnBuild=True/p:DeployTarget=MsDeployPublish/p:CreatePackageOnPublish=True/p:MSDeployPublishMethod=InProc/p:MSDeployServiceUrl=localhost/p:DeployIisAppPath="Default Web Site/NewOrleansJazz"/p:UserName=domainuser/p:Password=myPassword (来源)

请注意,在 VS11 Preview(在 BUILD 大会上发布)中,有一个新文件替换了 projectName.publish.xml:MyPublishSettings.pubxml.该文件基本上是 publish.xml 文件和 projectName.wpp.targets 的组合(但也为每个配置文件拆分,而不是将它们全部保存到 publish.xml 中,例如 TestSettings.pubxml、ProductionSettings.pubxml),并且可以使用 msbuild MyProject.csproj/t:WebPublish/p:PublishProfile="myProfile"

Note that in the VS11 Preview (released at the BUILD conference), there is a new file replacing the projectName.publish.xml: MyPublishSettings.pubxml. This file is basically a combination of the publish.xml file and the projectName.wpp.targets rolled into one (yet also split for each profile instead of having them all saved into publish.xml, e.g. TestSettings.pubxml, ProductionSettings.pubxml), and can be used from the command line in a simpler fashion using msbuild MyProject.csproj /t:WebPublish /p:PublishProfile="myProfile"

一些注释:您帖子中的信息:

[edit:] a couple notes re: the info in your post:

  1. 只指定单个项目的错误可能是由于指定的目标不正确.除了项目名称,传递给 msbuild 的所有参数都以 / 开头,例如/t[arget]:foo/p[roperty]:var=value
  2. Publish 目标实际上与 Web Publishing 无关.IIRC,它与发布 OneClick 应用程序有关.在 VS2010 中,您应该为 Web 项目使用 /t:build/p:DeployOnBuild=true 来使用发布任务(如上所示).VS11 中的新功能是 /t:WebPublish,它还采用一组更简单的参数,即您希望使用的 .pubxml 文件.
    • 附加说明:构建解决方案文件时,/t:WebPublish 将失败,因为目标未在解决方案级别定义.它只能在您的 Web 项目的项目文件上直接使用.您仍然可以在解决方案级别使用 /p:DeployOnBuild=true,因为参数值会传递给正在构建的每个项目,但不会被任何不使用该值的项目忽略.
  1. The error about only specifying a single project is probably due to specifying the target incorrectly. Other than the project name, all parameters passed to msbuild start with a /, e.g. /t[arget]:foo /p[roperty]:var=value
  2. The Publish target is actually not related to Web Publishing. IIRC, it's related to publishing a OneClick application. In VS2010, you should use /t:build /p:DeployOnBuild=true for Web projects to use the publishing tasks (as used above). New in VS11 is the /t:WebPublish which also takes a simpler set of parameters, namely the .pubxml file you wish to use.
    • additional note: when building a solution file, /t:WebPublish will fail as the target is not defined at the solution level. It can only be used directly on the project file for your Web project. You can still use /p:DeployOnBuild=true at the solution level as the parameter value is passed to each project being built, but will be ignored by any projects not consuming that value.

这篇关于如何从 powershell 执行与在 Visual Studio 中发布完全相同的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆