构建.NET项目具有可选的配置推荐方式可选、方式、项目、NET

2023-09-06 23:25:57 作者:我不做超人很久了i

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

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.

我看着简单pre-构建脚本,如从斯科特Hanselman的这个。它的工作原理,但我的问题是,pre-生成步骤修改源。只要建设项目将覆盖源文件和不必要的触发源控件修改。

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.

我还可以看看脚本VS /的MSBuild外的部署后,把​​配置文件在那里,但我真的希望还是有一个更好的办法。或许是自包含的VS / MSBuild的一种方式?

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?

我的部署策略到目标服务器是灵活的。我认为一个安装项目,这需要在包装前的配置进行。或者,一个XCOPY安装也是OK。

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.

想法?

推荐答案

更新01/09/2012 - 我开始使用团队构建这个项目,不想安装的 Windows SDK的的在我的构建机器。我做了一些研究,偶然发现 SlowCheetah ,这是在的路要走这一点。还有一个博客帖子获取这件事,并与团队建设运行。

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.

这是在app.config文件的Visual Studio XML转换。扩展什么放在了网页的家伙。虽然我没有计算任何的出来,以下是得到它设置极大的资源:

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:

您可以得到.targets以说明如何从的这篇文章。请务必阅读这些更新,在文章的最先进的最新信息的结束。

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.

您还需要从维沙尔·乔希的信息博客介绍如何设置一切都在你的项目。像下对方在解决方案资源管理得到.config文件嵌套简单的事情,给我带来的快乐!

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!

如果你没有它了,你需要安装.NET Framework 4.0 SDK,因为转换的东西从那里使用的工具。

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.

这些条款有提示和链接,让你去上进行改造的语法。这是pretty的直线前进后,您会看到一个或两个样本。

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.

祝你好运!