的MSBuild和MsDeploy多种环境 [英] MsBuild and MsDeploy with multiple environments
问题描述
是否有好的模式用于映射解决方案的配置,环境和使用MsDeploy每环境包装?
Are there good patterns for mapping solution configurations to environments and using MsDeploy for packaging per environment?
最短的版本:抓住这个文件,并尝试改变.msbuild文件,以便创建一个包年。 >
我有一个大量的类库和ASP.NET MVC应用程序的解决方案。我开车的构建与调用的主要解决方案的MSBuild的文件,然后做其他的事情。我想用新的msdeploy包装,以prepare的.zip文件供以后分配,但我有各种各样的困难。
I have a solution with a large number of libraries and an ASP.NET MVC application. I drive the build with an msbuild file that calls the main solution and then does other things. I want to use the new msdeploy packaging to prepare a .zip file for later distribution, but I'm having various difficulties.
我的解决方案有4种配置:本地
,开发
,测试
和 PROD
,这符合我想要映射到的环境。在该解决方案中,所有的图书馆都调试
和发布
模式,如平常。例如,在本地
解决方案模式下,所有的库编译调试
模式。然后,主应用程序的环境相匹配的解决方案,这样我可以有 Web.Dev.config
等,这似乎是要用的东西自然的方式。
My solution has 4 configurations: Local
, Dev
, Test
, and Prod
, which match the environments I want to map to. In that solution, all of the libraries have Debug
and Release
modes like usual. For example, in Local
solution mode, all libraries compile in Debug
mode. Then, the main application has matching environments with the solution, so that I can have Web.Dev.config
and so on, which seems like the natural way to use things.
如果我包是这样的:
<Target Name="BuildWebPackage">
<MSBuild Projects="..\Publisher\Site\Site.vbproj"
Targets="Package"/>
</Target>
我得到一个问题,即配置=本地
正确映射到了的库项目Site.vbproj
引用,它不能编译它们。
I get a problem where the Configuration=Local
is incorrectly mapped down to the library projects that Site.vbproj
references, and it can't compile them.
我看到两种可能的解决方案:一个我不能去工作的权利,另一个是极其丑陋
I see two possible solutions: one I can't get to work right, and the other is extremely ugly.
我试图调用通过该解决方案(在本例中包
目标,应用程序是解决方案文件夹中的网站项目是...我已经简化下来这个职位,因为在该解决方案实际上是多个应用程序。)
I attempt to call the Package
target via the solution (in this example, "Applications" is the solution folder that the Site project is in... I've simplified things down for this post because there are actually multiple applications in the solution.)
<Target Name="BuildWebPackage">
<MSBuild Projects="..\Publisher\Publisher.sln"
Targets="Applications\Site:Package"/>
</Target>
我觉得这个 SolutionFolder \项目名:目标
语法是如何做到这一点,因为:清洁
运行.. 。然而,这将引发
I think this SolutionFolder\ProjectName:Target
syntax is how to do this, because :Clean
runs... however, this throws
error MSB4057: The target "Applications\Site:Package" does not exist in the project.
尝试2
现在的丑陋的解决方案:它的工作原理,如果我改变我所有的库有4对那些4解决方案配置的其他配置。然而,这是丑陋的,真的很不错的计划,如果我想在以后共同开发的共享库与具有不同环境的项目。另外,这些环境无关的库,只有有意义的使用图书馆的顶级应用程序上下文。口味不好。
Attempt 2
Now for the ugly solution: it works if I modify ALL my libraries to have 4 additional configurations for those 4 solution configurations. However, this is ugly and really a bad plan if I want to co-develop a shared library later with a project that has different environments. Also, those environments have nothing to do with the library and only make sense in the context of the top-level applications using the libraries. Tastes bad.
我喜欢具有多个环境的解决方案,而花哨的新的Web.config更换的东西,但我不知道如何称呼msdeploy 包
任务这种情况,所以我可以在TeamCity的构建软件包。
I like having the multiple environments in the solution, and the fancy new Web.config replacement stuff, but I don't know how to call the msdeploy Package
task in this situation so I can build the package in TeamCity.
(请注意,我可能不希望调用msdeploy命令行,因为那是用来打开一个IIS应用程序到一个包,不是我在这里做。)
(Note that I probably do NOT want to call the msdeploy command line, because that's used to turn an IIS app into a package. Not what I'm doing here.)
此外,我一直在这里完全难住了,所以如果你想帮助的实验,我已经把这个样本解决方案。
Again, I've been completely stumped here, so if you want to help experiment, I've put together this sample solution.
推荐答案
第一次尝试失败,因为的包的目标并不在解决方案文件存在。当一个解决方案文件中使用的MSBuild,一个临时的MSBuild创建项目( SamplePackage.sln.metaproj 的);该项目的文件只包含一些目标(构建的清除的重建的的发布的 ,...)
The first attempt failed because Package target doesn't exist in the solution file. When using MSBuild on a solution file, a temporary MSBuild project is created (SamplePackage.sln.metaproj); this project file contains only some targets (Build, Clean, Rebuild, Publish, ...)
做你想做的一种方法是使用 DeployOnBuild 这样的属性:
One way to do what you want is to use DeployOnBuild property like this :
<PropertyGroup Condition="'$(Configuration)' == ''">
<Platform>Any Cpu</Platform>
<Configuration>Dev</Configuration>
<PackageLocation>$(MSBuildProjectDirectory)\package.zip</PackageLocation>
</PropertyGroup>
<Target Name="Build">
<MSBuild Projects="SamplePackage.sln"
Targets="Build"/>
</Target>
<Target Name="BuildWebPackage">
<MSBuild Projects="SamplePackage.sln"
Properties="Platform=$(Platform);
Configuration=$(Configuration);
DeployOnBuild=true;
DeployTarget=Package;
PackageLocation=$(PackageLocation);"/>
</Target>
- DeployOnBuild = TRUE :在构建被称为部署必须进行
- DeployTarget =包:为部署创建一个包
- PackageLocation :表示该包文件的文件路径
- DeployOnBuild=true : deployment must be made when Build is called
- DeployTarget=Package : for deployment creates a package
- PackageLocation : indicates the filepath of the package file
- 创建使用的MSBuild 网络包
- <一个href="http://stackoverflow.com/questions/2636153/how-can-i-get-tfs2010-to-run-msdeploy-for-me-through-msbuild">How我可以TFS2010通过MSBUILD运行MSDEPLOY我吗?
- <一个href="http://zvolkov.com/blog/post/2010/05/18/How-to-Publish-Web-Site-project-using-VS2010-and-MsBuild.aspx">How使用VS2010和的MSBuild 网站项目包/发布
- <一个href="http://blogs.msdn.com/b/aspnetue/archive/2010/03/05/automated-deployment-in-asp-net-4-frequently-asked-questions.aspx">Automated部署在ASP.NET 4 - 常见问题
- Creating web packages using MSBuild
- How can I get TFS2010 to run MSDEPLOY for me through MSBUILD?
- How to "Package/Publish" Web Site project using VS2010 and MsBuild
- Automated Deployment in ASP.NET 4 - Frequently Asked Questions
其他链接:
这篇关于的MSBuild和MsDeploy多种环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!