NET项目,我需要在其中基于某些编译符号在资源文件(这是一个xml文件)中添加内容。

类似于以下内容:

<xml ....>
<myNodes>

#if SOMECONDITION
<node1>
...
</node1>

#else
<node2>
...
</node2>

#endif
</myNodes>

这有可能吗?我知道这不符合XML规则。是否有类似的方法可以使用条件编译,但又要遵守XML规则?

最佳答案

我不确定100%可以解决您的问题,但您可以尝试使用条件构造。 xml中没有这样的条件编译。

 <rule>
    <if>
         <condition var="''$(Configuration)'" operator="=;">Debug</condition>
            <!-- more conditions possible -->
        </conditions>
        <statements>
            <!-- put your tage here -->
            <node1> ... </node1>
        </statements>
    </if>
    <else>
        <node2>
        ...
        </node2>
    </else>
</rule>

关于visual-studio-2010 - 如何在xml格式的resx文件中添加条件编译?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13500493/

10-14 16:40
查看更多