2015-02-18 9 views
5

Tak więc zaczynam grać z nugetem i jego wartościami są: web.config install/uninstall.xdt.Czyszczenie elementu xdt, jeśli nie ma dzieci

Moje pytanie brzmi: czy istnieje i xdt: przekształcenie, które usunie puste elementy. Nic tu nie znalazłem. https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx

Oto mój przykład.

Mój obecny Web.config.install.xdt wygląda to

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.web> 
    <compilation xdt:Transform="InsertIfMissing"> 
     <assemblies xdt:Transform="InsertIfMissing"> 
     <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)" assembly="MyAssembly, Version=4.5.4.0, Culture=neutral, PublicKeyToken=asdfasdfasdfasdf" /> 
     </assemblies> 
    </compilation> 
    </system.web> 
</configuration> 

i mój odinstalować wygląda to

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.web> 
    <compilation> 
     <assemblies> 
     <add xdt:Transform="Remove" xdt:Locator="Match(assembly)" assembly="MyAssembly, Version=4.5.4.0, Culture=neutral, PublicKeyToken=asdfasdfasdfasdf" /> 
     </assemblies> 
    </compilation> 
    </system.web> 
</configuration> 

Oto mój web.config przed (uproszczony)

<system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 

Oto mój plik web.config po instalacji.xtd

<system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
     <add assembly="MyAssembly, Version=4.5.4.0, Culture=neutral, PublicKeyToken=asdfasdfasdfasdf" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 

Oto mój web.config po deinstalacji

<system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 

Czy mimo to, aby pozbyć się znacznika?

Odpowiedz

5

Wygląda na to, że można podać wiele transformacji elementu. Dlatego możesz usunąć zawartość z instalacji, a następnie sprawdzić, czy element ma dzieci, a jeśli nie, usunąć ten element.

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.web> 
    <compilation> 
     <assemblies> 
     <add xdt:Transform="Remove" xdt:Locator="Match(assembly)" assembly="MyAssembly, Version=4.5.4.0, Culture=neutral, PublicKeyToken=asdfasdfasdfasdf" /> 
     </assemblies> 
     <assemblies xdt:Locator="Condition(count(*) = 0)" xdt:Transform="Remove"/> 
    </compilation> 
    </system.web> 
</configuration> 
+0

Wow, dzięki, postaram się przetestować Twoje rozwiązanie tak szybko, jak to możliwe. Będę musiał odświeżyć mój kod, minęło trochę czasu. – Lareau

+0

dziękuję, spróbowałem tego dziś rano i zadziałało jak urok. Dobra informacja. – Lareau

+0

Wielka wskazówka, dzięki – resp78