【问题标题】:add reference to assembly in XSLT C# script block在 XSLT C# 脚本块中添加对程序集的引用
【发布时间】:2015-03-10 18:45:43
【问题描述】:

我正在尝试在嵌入 XSLT1.0 文档的 C# 脚本块中使用字典。 当我尝试添加对 System.Collections.Generic 或 System.Core 的引用时,我得到一个“找不到程序集的元数据文件......” 将 ref 添加到“mscorlib”时,似乎引用了旧版本(?),因为我在尝试使用 Dictionary.Keys.Contains() 时遇到错误(“不包含包含方法)。 不用说,这段代码在 xslt 之外测试成功。 如何向 FW 3.5/4 添加适当的参考? 天呐!

【问题讨论】:

  • 分享源代码的关键部分可能有助于其他人深入了解您的问题。另外,请检查:how to ask good questions

标签: c# xslt reference .net-assembly


【解决方案1】:

Dictionary.Keys.Contains 定义在 System.Linq 命名空间中,而 Linq 定义在 System.Core 程序集中,因此您需要正确的 msxsl:assemblymsxsl:using 元素。以下在 VS2013 XSLT 调试器中对我有用:

<msxsl:script implements-prefix="my" language="csharp">
  <msxsl:assembly name="System.Core" />
  <msxsl:using namespace="System.Linq" />
  <msxsl:using namespace="System.Collections.Generic" />

  <![CDATA[
    public bool myFunc() 
    {
      var d = new Dictionary<string, string>();
      d.Add("Hello", "Goodbye");
      return d.Keys.Contains("Hello");
    }    
  ]]>
</msxsl:script>

这仍然留下了您为什么使用Dictionary.Keys.Contains 的问题,什么时候可以使用Dictionary.ContainsKey,它从 .NET 2.0 开始就已经存在并且不需要任何额外的程序集或命名空间引用。

【讨论】:

  • Thanks.Using ContainsKey 确实解决了“无方法”问题,但是我仍然无法引用 System.Linq、Collections.Generic 或 Core。有任何想法吗? VS2010 顺便说一句
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多