0

I have followed the following post Nuget Config.Transform Formatting Issue to add web.config file entries in NuGet.

I have used the below xdt file in my NuGet package

    <compilation>
        <assemblies>
            <add assembly="ASSEMBLY1, Version=1.0.10, Culture=neutral" xdt:Transform="Insert"/>
            <add assembly="ASSEMBLY2, Version=1.0.11, Culture=neutral" xdt:Transform="Insert"/>
            <add assembly="ASSEMBLY3, Version=1.0.12, Culture=neutral" xdt:Transform="Insert"/>
            <add assembly="ASSEMBLY4, Version=1.0.13, Culture=neutral" xdt:Transform="Insert"/>
        </assemblies>
    </compilation>
</system.web>

and i have tried to install this NuGet am getting the following error. Error An error occurred while applying transformation to 'web.config' in project 'WebApplication60' No element in the source document matches '/configuration/system.web/compilation/assemblies/add' 0

Since the assemblies node was not found in the project. I have tried to add xdt:Transform="Insert" to assemblies node, but it causes duplicate entries in web.configfile like below

<assemblies>
                <add assembly="ASSEMBLY1, Version=1.0.10, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY2, Version=1.0.11, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY3, Version=1.0.12, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY4, Version=1.0.13, Culture=neutral" xdt:Transform="Insert"/>
<add assembly="ASSEMBLY1, Version=1.0.10, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY2, Version=1.0.11, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY3, Version=1.0.12, Culture=neutral" xdt:Transform="Insert"/>
                <add assembly="ASSEMBLY4, Version=1.0.13, Culture=neutral" xdt:Transform="Insert"/>
            </assemblies>

How to avoid this duplicate entries?

4

1 回答 1

0

为避免插入重复条目,您可以尝试先删除assemblies元素(如果有),然后插入一个已填充<add assembly=""/>元素的新元素:

<compilation>
    <assemblies xdt:Transform="Remove"/>
    <assemblies xdt:Transform="Insert">
        <add assembly="ASSEMBLY1, Version=1.0.10, Culture=neutral"/>
        <add assembly="ASSEMBLY2, Version=1.0.11, Culture=neutral"/>
        <add assembly="ASSEMBLY3, Version=1.0.12, Culture=neutral"/>
        <add assembly="ASSEMBLY4, Version=1.0.13, Culture=neutral"/>
    </assemblies>
</compilation>

或者,您可以尝试使用InsertIfMissingtransform 插入 while 元素并避免重复,以防它已经存在:

<compilation>
    <assemblies xdt:Transform="InsertIfMissing">
        <add assembly="ASSEMBLY1, Version=1.0.10, Culture=neutral" 
             xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)"/>
        <add assembly="ASSEMBLY2, Version=1.0.11, Culture=neutral"
             xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)"/>
        <add assembly="ASSEMBLY3, Version=1.0.12, Culture=neutral"
             xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)"/>
        <add assembly="ASSEMBLY4, Version=1.0.13, Culture=neutral"
             xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)"/>
    </assemblies>
</compilation>
于 2016-05-19T05:27:39.783 回答