在运行时使用资源编译 VB.NET 项目

问题描述 投票:0回答:1

我的应用程序将一组 VBScript(UTF8 文本文件)捆绑到 VB.NET 程序集中。我曾经将脚本代码作为 String 成员嵌入到类中,但事实证明这是一个糟糕的设计。我想将它们作为资源包含在内。将资源添加到 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 resources
1个回答
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")
© www.soinside.com 2019 - 2024. All rights reserved.