Failed to convert web.config if no value exists for the conversion

Today we had an incident that made me think. We have a project with a fairly standard configuration for web.config conversion for different configurations. There is a section that 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 such a conversion:

 <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)" /> 

I hope you noticed an error here - the name for DaoEndPoint does not match. Unfortunately, the developer who created it did not perform local debugging regarding live services, which is why the test deployment, yup, pointed to live . Fortunately, we quickly picked it up, but I'm sure you can see the potential danger here!

I thought about your intentions when creating the transformation files, and it seems to me that if you introduce a transformation, you intend to convert something . Therefore, it would be nice if the conversion (and therefore the deployment) were unsuccessful if there was a DaoEndPoint transformation, but there was no corresponding DaoEndPoint element in the main .config file.

So, Iā€™m sort of collecting the opinions of people, is that what would be useful? Is this too much? Have I completely missed the point?

Also, is there anything that does this? I am happy to fork out and develop a solution, but I would be happier if someone did the work for me;)

+6
source share
1 answer

See Sayed Ibrahim Hashimi for an excellent answer to this question , which includes creating a custom class that inherits from Microsoft.Web.Publishing.Tasks.Transform . You can use the same method, but instead inherit from the Locator class, and then throw an exception if you cannot match the target node.

I myself experienced this and was able to eliminate the exception at the time of publication. However, my custom locator class ( MyMatch ) actually did nothing, except that it threw an exception. Perhaps it would be nice to work to redefine methods that mimic the Match class (which you cannot inherit from) and then figure out a suitable place for a final check for non-compliance.

In any case, I definitely think it would be useful, at least, to be able to set where the publication will fail, or give you a warning when your conversion has not affected.

+1
source

Source: https://habr.com/ru/post/910824/


All Articles