问题描述
想在这里挑选那些 MS Build/VS Post 构建指数的大脑.
我希望根据用户/机器/环境自定义我的 web.config 条目.
我可以在 web.config 中标记我的可配置/可更改条目,并希望这些条目被相应的用户/环境文件覆盖,并希望有一个顺序来决定如果找到条目应该优先于另一个条目在多个文件中.
例如:web.config 有一个 $connectionstring 条目,每个用户/环境的自定义文件可能具有替换 $connectionstring 的潜在值,具体取决于构建解决方案的上下文/配置
这意味着,我可以拥有如下一组文件:
user_joe.config
$connectionstring = db_where_joe_like_to_connect_to
staging.config
$connectionstring = db_where_staging_connect_to
生产.config
$connectionstring = db_production
因此,如果 joe 正在从他的开发框中编译解决方案,则 web.config 的 $connectionstring 应该具有值db_where_joe_like_to_connect_to".
我希望有一个不涉及 Nant 的解决方案.
希望有人能指点一下.
您可以使用 Visual Studio 2010 的 web.config 转换设置.
这将允许每个开发人员拥有可以合并到其构建设置中的 web.config 部分.
在内部,我们使用从网络上不同地方拼凑而成的事件——因为这通常发生在发布期间,我们希望它发生在编译时.
添加一个 BeforeBuild 目标所以 - 从 csproj 文件中:
<目标名称=BeforeBuild"><TransformXml Source=$(SolutionDir)Web.config";Transform=$(SolutionDir)Web.$(Configuration).config"目的地=$(SolutionDir)Web.$(Configuration).config.transformed"/></目标><属性组><PostBuildEvent>xcopy $(SolutionDir)Web.$(Configuration).config.transformed"$(SolutionDir)Web.config"/R/Y</属性组>Wanted to pick the brains of those MS Build/ VS Post build exponents here.
I would like to have my web.config entries customizable per user/machine/environment.
I could have my configurable/changeable entries marked in the web.config and would like those entries overridden by the respective user/environment file and would like to have an order that decides which entries should trump the other if the entry is found in multiple files.
for eg: web.config has a $connectionstring entry and the customization files per user/environment could have the potential values to replace $connectionstring depending on the context/configuration the solution is built
which means, I could have a set of files like below:
user_joe.config
$connectionstring = db_where_joe_like_to_connect_to
staging.config
$connectionstring = db_where_staging_connect_to
production.config
$connectionstring = db_production
so if joe is compiling the solution from his Dev box, the web.config should have the value "db_where_joe_like_to_connect_to" for $connectionstring.
I am hoping there could be a solution that doesn't involve Nant.
hope someone can throw pointers.
You can use visual studio 2010's web.config transform settings.
This will allow each developer to have their portion of a web.config that can get merged in for their build settings.
Internally we use an event that was pieced together from various places on the net- since normally this happens during publishing and we wanted it to happen at compile time.
Add a BeforeBuild targetSo - from the csproj file:
<Target Name="BeforeBuild"> <TransformXml Source="$(SolutionDir)Web.config" Transform="$(SolutionDir)Web.$(Configuration).config" Destination="$(SolutionDir)Web.$(Configuration).config.transformed" /> </Target> <PropertyGroup> <PostBuildEvent>xcopy "$(SolutionDir)Web.$(Configuration).config.transformed" "$(SolutionDir)Web.config" /R /Y</PostBuildEvent> </PropertyGroup>
这篇关于Visual Studio 2010 - 每个开发人员/机器/环境 Web.Config 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!