LINQ未经本人同意生成实体

本文关键字:实体 LINQ | 更新日期: 2023-09-27 18:00:23

我有这个代码C#来创建XElement:

XNamespace ns = "http://schemas.microsoft.com/wix/2006/wi";
XElement elem = new XElement (ns + "CustomAction", new Object[] {
                                new XAttribute("Id", "shellex"), new XAttribute("Directory", "WINDOWSVOLUME"), new XAttribute("Impersonate", "no"), 
                                new XAttribute("ExeCommand", @"cmd.exe /c move "C:'Documents and Settings'test.txt" "C:'" "), 
                                new XAttribute("Return", "asyncNoWait")});

我有一个函数,可以将特定节点上的XElement添加到XML文件中。

因此,程序在我的XML文件上生成以下行:

<CustomAction Id="shellex" Directory="WINDOWSVOLUME" Impersonate="no" 
ExeCommand="cmd.exe /c move &amp;quot;C:'Documents and Settings'test.txt&amp;quot; &amp;quot;C:'&amp;quot; " Return="asyncNoWait" />

LINQ在&quot;之前生成&amp;实体,因此我的ExeCommand无法工作。

但我不明白LINQ为什么会生成这个。如何取消生成&amp;

LINQ未经本人同意生成实体

您需要转义报价,有两种方法可以做到这一点:

在常规字符串中使用反斜杠:

'"

在@分隔的字符串中使用双引号:

""

这应该有效:

new XAttribute("ExeCommand", @"cmd.exe /c move ""C:'Documents and Settings'test.txt"" ""C:'""; "),