this question kind of 2 parter. in vs2015 mvc project has multiple different build configurations, test, uat, live etc. web.config can right click , select add config transform create transform files each build configuration.
if have external config file, such log4net.config how can configure have dependant transforms web.config ? done manually editing project.csproj file ?
secondly, have web.config file :
<configuration> <configsections> <section name="log4net" type="log4net.config.log4netconfigurationsectionhandler, log4net" /> </configsections> ... <log4net configsource="log4net.config" /> </configuration> when build project, web.config automatically gets transformed through following afterbuild target in project.csproj file :
<target name="afterbuild"> <transformxml source="web.config" transform="web.$(configuration).config" destination="$(outputpath)\$(assemblyname).config" /> </target> how can transform included log4net.config file using same configuration transformation ? realise place transformxml afterbuild target, correct way of doing transform, or missing ?
i opted solution of using base log4net.config file, log4net.xxx.config file each build configuration , additional transformxml task in afterbuild target :
- log4net.config
- log4net.debug.config
- log4net.release.config
- log4net.test.config
- log4net.uat.config
the project.csproj file looks :
<content include="log4net.config"> <copytooutputdirectory>always</copytooutputdirectory> </content> <none include="log4net.debug.config"> <dependentupon>log4net.config</dependentupon> </none> <none include="log4net.release.config"> <dependentupon>log4net.config</dependentupon> </none> <none include="log4net.test.config"> <dependentupon>log4net.config</dependentupon> </none> <none include="log4net.uat.config"> <dependentupon>log4net.config</dependentupon> </none> .... <target name="afterbuild"> <transformxml source="web.config" transform="web.$(configuration).config" destination="$(outputpath)\$(assemblyname).config" /> <transformxml source="log4net.config" transform="log4net.$(configuration).config" destination="$(outputpath)\log4net.config" /> </target> and example log4net.test.config looks (i using transform change connection strings , log4net's logging level) :
<?xml version="1.0" encoding="utf-8"?> <log4net xmlns:xdt="http://schemas.microsoft.com/xml-document-transform"> <appender> <connectionstring value="data source=example.com;initial catalog=examplelogs;user id=xxx;password=xxx" xdt:transform="replace" /> </appender> <root> <level value="debug" xdt:transform="replace" /> </root> </log4net> this transforms log4net.config file in output path successfully. uses same approach transforming web.config files , should understandable other developer picks project.
whilst works , has been in production while now, i'm still looking confirmation correct way of doing transforms of included config files.
Comments
Post a Comment