如何通过命令行将MSDeploy样式的参数传递给MSBuild? [英] How can I pass MSDeploy-style parameters to MSBuild via the commandline?

查看:100
本文介绍了如何通过命令行将MSDeploy样式的参数传递给MSBuild?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置TeamCity以将我们的Website Project应用程序(使用* .wdproj)和Web Deploy应用程序部署到IIS.

I am setting up TeamCity to deploy our Website Project application (using a *.wdproj) and Web Deploy application to IIS.

我有一个使用MSBuild.exe和MSDeployPublish进行构建,然后部署该应用程序的构建配置.

I have a build configuration that uses MSBuild.exe with the MSDeployPublish to build and then deploy the application.

我们现在希望将应用程序部署到多个目标环境,因此需要一种基于目标环境提供不同设置的方法.

We now want to get the application to deploy to multiple target environments, therefore need a way to supply different settings based on the target environment.

我已向Web部署项目中添加了parameters.xml文件,并验证了此处设置的参数一直贯穿目标IIS服务器并正确应用-太好了!

I have added a parameters.xml file to the Web Deployment Project, and have verified that the parameters set in here are making all the way through the target IIS server and being correctly applied - great!

现在,我要针对每个环境进行不同的参数设置.我希望可以使用MSDeploy.exe -setParam参数之类的东西为每个环境指定不同的值,但是我找不到通过命令行将参数值输入MSBuild的方法.

Now what I want to do is have different parameter settings per environment. I was hoping I could use something like the MSDeploy.exe -setParam argument to specify different values for each environment, however I can find no way to get my parameter values into MSBuild via the commandline.

我怀疑我可能需要执行以下一项操作:

I suspect I might need to do one of the following:

  1. 将MSBuild和MSDeploy拆分为单独的构建步骤.

  1. Split MSBuild and MSDeploy into separate build steps.

在管道中的某个位置配置一个任务,以获取n.版本的parameter.something.xml中的1个并将其移入parameters.xml,以便其他管道将其拾取.

Configure a task somewhere in the pipeline to take 1 of n versions of parameters.something.xml and move it into parameters.xml so it gets picked up by the rest of the pipeline.

目前,我正在寻找最简单的方法,欢迎提出任何建议.

I'm looking for the simplest way to move ahead at this point, any suggestions welcome.

作为参考,这是我现在正在尝试的命令:

For reference, here is the command I'm experimenting with now:

msbuild /target:MSDeployPublish MySite_deploy.wdproj /P:Configuration=Debug
/P:DeployOnBuild=True /P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=www.myserver.com:8172/MsDeploy.axd
/P:AllowUntrustedCertificate=True /P:MSDeployPublishMethod=WMSvc
/P:CreatePackageOnPublish=True /P:UserName=MyUser /p:Password=MyPassword
/P:DeployIisAppPath=www.myserver.com/MySite
/P:ServerURL=http://www.tryingtoforcethis.com

除了ServerURL的值(这是我在我的parameters.xml中定义的一个参数)没有进入目标站点之外,它的运行很漂亮.但是,我在parameters.xml中指定的默认值是.因此,我知道参数可以正常工作,只是无法弄清楚如何将其添加到msbuild命令行中.

It's working beautifully except the value for ServerURL, which is a parameter I've defined in my parameters.xml, is not making its way into the target site. The default I specified in parameters.xml, however, is. So I know that the parameters are working, I just can't figure out how to add them to the msbuild commandline.

推荐答案

好吧,我认为简短的答案是,使用MSBuild 4.0和VS2010,您不能只是从对MSBuild的调用中将任意参数传递给MSDeployPublish.

Well, I think the short answer is that with MSBuild 4.0 and VS2010, you can't just pass arbitrary parameters into MSDeployPublish from the call to MSBuild.

我发现这些帖子很有帮助:

I found these posts helpful:

http://forums.iis.net/t/1167657.aspx/1 -陈铭的评论

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingIMPprovementsChained -底部的Richard Szalay的评论

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.aspx - the comments from Richard Szalay at the bottom

阅读这些内容,并在Microsoft.Web.Publishing.targets文件中筛选了一段时间之后,试图找到一种方法",我最终决定在源代码管理的项目文件夹中拥有Parameters.xml的多个副本,根据其环境进行标记,例如:

After reading these, and sifting through the Microsoft.Web.Publishing.targets file for some time trying to find a "way in", I finally settled on having multiple copies of Parameters.xml in my project folder in source control, labelled according to their environment eg:

  • Parameters.Test.xml
  • Parameters.Staging.xml
  • Parameters.Live.xml

然后,在打包和部署之前,我只将其中一个文件复制到Parameters.xml中,其余的管道就会将其拾取-完成!

Then, prior to the package and deploy, I just copy one of these files into Parameters.xml and it gets picked up by the rest of the pipeline - done!

顺便说一句,由于似乎是某种文件访问问题,我暂时无法在单个MSBuild.exe调用中获取parameters.xml副本并随后进行清理,我在这里进行了详细说明:

BTW I had a temporary problem getting the parameters.xml copy and subsequent cleanup to work within a single MSBuild.exe call due to what seems to be some sort of file access issue, I've detailed it here:

MSBuild除非目标文件中已经存在该文件的版本,否则.exe复制任务无法正常工作

这篇关于如何通过命令行将MSDeploy样式的参数传递给MSBuild?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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