MSBuild-如何强制执行"AfterBuild"何时部署的目标? [英] MSBuild - how to force "AfterBuild" target when I do deployment?

查看:214
本文介绍了MSBuild-如何强制执行"AfterBuild"何时部署的目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置:ASP.Net MVC .Net 4.0解决方案,其中包含5个项目,以及几种解决方案配置( Site1-Stage,Site1-Live,Site2-Stage 等).原因很简单-我们将相同的代码库部署到具有不同配置设置的多台服务器上.

I have the following setup: ASP.Net MVC .Net 4.0 solution with 5 projects in it, and several solution configurations (Site1-Stage, Site1-Live, Site2-Stage, etc). The reason for this is simple - we deploy same codebase to multiple servers with different config settings.

要管理这些配置,我使用Troy Hunt在他的您将其部署错误! TeamCity,Subversion& Web Deploy第1部分:配置转换文章.用两个词-我的SVN存储库中没有 web.config ,相反,我有 Web.Base.Config Web.Site1-Stage.Config 等,以及项目 AfterBuild 目标中的 XmlTransformation 任务.在构建过程中,根据选定的配置生成所需的 web.config :

To manage these configurations, I use the approach described by Troy Hunt in his You're deploying it wrong! TeamCity, Subversion & Web Deploy part 1: Config transforms article. In 2 words - I do NOT have web.config in my SVN repo, instead I have Web.Base.Config, Web.Site1-Stage.Config, etc and XmlTransformation task in project AfterBuild target. During the build, the required web.config is generated based on selected configuration:

 <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="AfterBuild">
    <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" StackTrace="true" />
  </Target>

这是问题所在::当我这样执行MSBuild时:

Here comes the problem: when I'm execute MSBuild like this:

msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild

一切顺利,为 Site1-Stage 配置正确生成了web.config.但是,如果我运行以下命令:

all goes well, web.config is properly generated for the Site1-Stage configuration. However, if I run this command:

msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild /P:DeployOnBuild=True

我收到以下错误:

"MySolution.sln"(重建目标)(1)->"MySolution \ MyWebProj.csproj" (重建目标)(3)->(PreTransformWebConfig目标)-> C:\ Program 档案文件 (x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.5 \ Web \ Microsoft.Web.Publishing.targets(1399,5): 错误:将文件Web.config复制到 obj \ Site1-Stage \ TransformWebConfig \ original \ Web.config失败.可以 找不到文件"Web.config". [MySolution \ MyWebProj.csproj]

"MySolution.sln" (rebuild target) (1) -> "MySolution\MyWebProj.csproj" (Rebuild target) (3) -> (PreTransformWebConfig target) -> C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.5\Web\Microsoft.Web.Publishing.targets(1399,5): error : Copying file Web.config to obj\Site1-Stage\TransformWebConfig\original\Web.config failed. Could not find file 'Web.config'. [MySolution\MyWebProj.csproj]

我试图将"AfterBuild"目标明确添加到MSBuild命令行中:

I tried to explicitly add "AfterBuild" target into MSBuild command line:

msbuild MySolution.sln /P:configuration=Site1-Stage /t:rebuild,AfterBuild /P:DeployOnBuild=True

但是它导致了相同的错误.

but it resulted in the same error.

我为什么需要这个:这是一个非常孤立的示例,实际上,我正在尝试从TeamCity CI服务器设置自动发布.我认为,如果在当前发布步骤之前使用"Visual Studio(sln)"运行器添加新的构建步骤,那将可行,它将首先重新构建项目(并生成web.config)-然后进行发布.但是,我有很多发布步骤(现在大约有20个步骤),我想避免这种情况.我的理解是,发布"过程会将构建作为其一部分进行,因此我想重用"该过程.

Why do I need this: it's a very isolated example, and in reality I'm trying to setup automated publishing from TeamCity CI server. I think if I add new build step with "Visual Studio (sln)" runner BEFORE my current publishing step, that would work, it will first rebuild the project (and generate web.config) - and then publish. However, i have lots of publishing steps (around 20 now) and I would like to avoid that. My understanding is that "Publish" process does the build as part of it, so I would like to "reuse" that.

问题是:我应该如何修改MSBuild命令行以强制进行配置转换?

Question is: how should I modify my MSBuild command line to force config transformation to happen?

谢谢.

推荐答案

也许使用"BeforeBuild"?

Maybe use "BeforeBuild"?

顺便说一句,csproj中是否包含web.config?我相信大多数发布活动都依赖于项目而不是文件夹中的项目.您可以在项目中包含web.config,但仍将其从源代码管理中排除.

BTW do you have web.config included in csproj? I believe most publish activities relies on items in project rather than in folder. You can include web.config in project, while still have excluded it from source control.

这篇关于MSBuild-如何强制执行"AfterBuild"何时部署的目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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