【问题标题】:Compiling VB.NET project at runtime with resources在运行时使用资源编译 VB.NET 项目
【发布时间】:2009-09-22 13:30:32
【问题描述】:

我的应用程序将一组 VBScript(UTF8 文本文件)捆绑到一个 VB.NET 程序集中。我曾经将脚本代码作为字符串成员嵌入到类中,但事实证明这是一个糟糕的设计。我想将它们作为资源包含在内。向 CompilerParams 添加资源的最佳方式是什么?

到目前为止我得到了什么(不包括所有的错误检查):

  Dim comParams As New CompilerParameters()
  comParams.OutputAssembly = DLL_Path
  comParams.ReferencedAssemblies.Add("System.dll")
  comParams.ReferencedAssemblies.Add("System.Windows.Forms.dll")
  comParams.ReferencedAssemblies.Add("System.Drawing.dll")
  comParams.ReferencedAssemblies.Add("mscorlib.dll")
  comParams.ReferencedAssemblies.Add(RhinoDotNETSDKPath)

  comParams.WarningLevel = 3
  comParams.CompilerOptions = "/target:library /optimize"

  comParams.GenerateExecutable = False
  comParams.GenerateInMemory = False

  Dim iCode As String = Me.DotNETSource

  Dim iProvider As CodeDomProvider = CodeDomProvider.CreateProvider("VB")
  comResult = iProvider.CompileAssemblyFromSource(comParams, New String() {iCode})

CompilerParameters 包含 EmbeddedResources 和 LinkedResources 的字段,但从我目前发现的示例来看,这些似乎只与框架资源有关???

【问题讨论】:

    标签: vb.net compiler-construction resources


    【解决方案1】:

    您刚刚尝试过EmbeddedResources 属性吗?

    Dim resources As new StringCollection
    resources.Add("foo/bar.txt")
    resources.Add("data/file.xml")
    comParams.EmbeddedResources = resources
    

    我还没有检查(很快会检查),但我认为应该可以正常工作。如果它不适合您,请在尝试时详细说明问题所在。

    我相信如果你想在程序集中更改名称,你会使用类似的东西:

    resources.Add("foo/bar.txt,testdata.bar.txt")
    

    【讨论】:

    • @Jon,抱歉回复晚了, 忘了我问了这个问题。我认为这确实是答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多