简体   繁体   中英

Failing web.config transform when no value exists for a transform

We had a bit of an incident today which has got me thinking. We have a project with a pretty standard web.config transform setup for our various configs. There is a section which controls access to our DAO services which looks like this:

<endpoint address="http://myserver/myservice1.svc/basicHttp"
binding="basicHttpBinding" contract="MyAssembly.IItem" name="DataAccessEndPoint"
kind="" endpointConfiguration="" />
<endpoint address="http://myserver/myservice2.svc/basicHttp"
binding="basicHttpBinding" contract="MyAssembly.IItem2" name="LoggingEndPoint"
kind="" endpointConfiguration="" />

And a transform like this:

<endpoint address="http://mytestserver/myservice1.svc" name="DaoEndPoint" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"  />
<endpoint address="http://mytestserver/myservice2.svc" name="LoggingEndPoint" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"  />

Hopefully you will have spotted the error here - the name for the DaoEndPoint doesn't match. Unfortunately the dev who created it didn't, and had also been locally debugging against the live services, which caused the test deployment to, yup, point to live . We luckily picked it up pretty quickly, but I'm sure you can see the potential for extreme pain here!

I got thinking about your intent when creating transform files and it seems to me that if you put in a transform that you intend to transform something . So it would be nice if the transform (and therefore the deploy) failed if there was a DaoEndPoint transform but no matching DaoEndPoint item in the main .config file.

So I'm sort of canvasing for people's opinions, is this something that would be useful? Is it plain overkill? Am I totally missing the point?

Also, is there anything out there that does this? I'm happy to dig about and develop a solution, but I'd be happier if someone had done the legwork for me ;)

See Sayed Ibrahim Hashimi's great answer to this question , which involves creating a custom class that inherits from Microsoft.Web.Publishing.Tasks.Transform . You could use the same technique but inherit from the Locator class instead, and then throw an exception when you are unable to match a target node.

I actually tested this myself and was able to have the exception thrown during publishing. However, my custom locator class ( MyMatch ) didn't actually do anything besides throw the exception. It might be a fair bit of work to override methods to mimic the Match class (which you can't inherit from) and then figure out the appropriate place to do a final check for a failure to match.

Anyway, I definitely think it would be useful to at least have an option that you could set where publishing would fail or give you a warning when your transform had no effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM