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

查看:182
本文介绍了如何执行与从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时;然后右键单击该项目,然后选择发布";出现一个对话框,您再次单击发布"以填写一些设置.它神奇地将您的网站按预期推出.它还会创建一个文件来保存这些设置. projectName.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.

我看过仅生成(从包含.csproj的目录运行的)"msbuild target:publish":

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的几种变体.可以这么难!!如果您可以在Studio中右键单击,则可以执行某些任务.

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/zh-cn/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=domain\user /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:]一些注意事项:帖子中的信息:

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

  1. 仅指定一个项目的错误可能是由于错误地指定了目标.除项目名称外,传递给msbuild的所有参数均以/开头,例如/t[arget]:foo /p[roperty]:var=value
  2. 发布"目标实际上与Web发布无关. 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天全站免登陆