在几个项目的App.config文件中,有一行
<add key="url" value="http://www.example.com/"/>
每次构建时,我都希望有一项任务来验证"url"
密钥不是否包含文本"http://localhost"
。有没有办法做到这一点?
答案 0 :(得分:1)
我假设您有一个团队,并且您的一些团队成员无意中检查了这些配置,将该值更改为localhost。
如果是这种情况,为什么不为每个环境转换文件,您的调试配置可以将密钥设置为localhost,而您的生产/测试/阶段/ qa /任何配置都可以将其设置为example.com或其他内容其他
您可能没有意识到msbuild可以转换您的配置文件。基本上,您拥有主配置文件,然后是每个环境包含仅更改内容的配置文件。在进行构建时,msbuild将使用另一个中的更改修改主要的#34;转换&#34;文件。
App.Config Transformation for projects which are not Web Projects in Visual Studio 2010?
您的转换文件如下所示:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="url" value="http://www.example.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
</appSettings>
</configuration>
Microsoft链接到http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
它们可以很容易地在web.configs和app.configs上使用,只需稍微调整一下你的项目文件。
答案 1 :(得分:0)