建议使用可选配置构建.NET项目的方法 [英] Recommended way to build a .NET project with selectable configurations

查看:154
本文介绍了建议使用可选配置构建.NET项目的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个可以成功构建的.NET项目。现在,我需要选择性地构建到不同的环境,如DEV,QA和PROD。每个都需要自己的配置文件(例如app.config)来包含相应的连接字符串和其他设置。



我看过简单的预构建脚本,如Scott Hanselman的这一个。它的工作原理,但我的问题是,预构建步骤修改源。简单地构建项目将覆盖源文件并不必要地触发源代码管理修改。



我还可以查看VS / MSBuild之外的脚本,将配置文件放在部署,但我真的希望还有更好的方法。也许一种在VS / MSBuild中是独立的方式?



我对目标服务器的部署策略是灵活的。我考虑过一个安装项目,这将需要在打包之前进行配置。或者,xcopy安装也可以。



想法?

解决方案

p> 更新01/09/2012 - 我开始为此项目使用Team Build,并且不想在我的构建机器上安装 。我做了一些研究,偶然发现了 SlowCheetah ,这是 的方式去做。还有一个博客文章,以便使用Team Build进行运行。






Visual Studio XML转换在app.config文件上。扩展了为网络家伙提供的内容。虽然我没有任何想法,以下是设置好的资源:



您可以获取.targets文件,说明如何使用来自这篇文章。请确保您阅读文章末尾的更新以获取最新信息。



您还需要 Vishal Joshi的博客,介绍如何在项目中设置所有内容。简单的事情就是让.config文件在解决方案资源管理器中嵌套在一起,带给我快乐!



如果你还没有,你需要安装.NET Framework 4.0 SDK,因为转换内容使用的工具就是从那里。



这些文章有提示和链接,可以让您了解转换语法。看到一两个样子后,这很简单。



祝你好运!


Suppose I have a .NET project that builds successfully. Now, I need to selectively build to different environments, such as DEV, QA, and PROD. Each require their own config files (app.config for instance) to contain corresponding connection strings and other settings.

I've looked at simple pre-build scripting, such as this one from Scott Hanselman. It works, but my problem is that the pre-build step modifies the source. Simply building the project will overwrite source files and unnecessarily trigger source control modifications.

I could also look into scripting outside of VS/MSBuild to put the config files in there after the deployment, but I'm really hoping there's still a better way. Perhaps a way that's self-contained in VS/MSBuild?

My deployment strategy to the target server is flexible. I've considered a setup project, which would require the configuration take place before the packaging. Or, an xcopy install is ok, too.

Ideas?

解决方案

UPDATE 01/09/2012 - I started using Team Build for this project and didn't want to install the Windows SDK on my build machine. I did some research and stumbled across SlowCheetah, which is the way to go for this. There is also a blog post for getting this up and running with Team Build.


Visual Studio XML Transformations on the app.config files. Extending what was put in for the web guys. While I didn't figure any of it out, the following are great resources for getting it set up:

You can get the .targets file with instructions on how to use it from this article. Make sure you read the updates at the end of the article for the most up-to-date info.

You'll also need the information from Vishal Joshi's blog that describes how to set up everything in your project. Simple things like getting the .config files to nest under each other in the solution explorer bring me joy!

If you don't have it already, you'll need to install the .NET Framework 4.0 SDK since the transform stuff uses a tool from there.

Those articles have hints and links to get you going on the transformation syntax. It's pretty straight forward after you see a sample or two.

Good luck!

这篇关于建议使用可选配置构建.NET项目的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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