c# - CodeDom ReferencedAssemblies 绝对路径

标签 c# .net wpf assemblies codedom

我正在用 WPF 表单 创建一个新的 .exe。问题是,我需要引用一些程序集。

这是我添加它们的方式:

var p = new CompilerParameters
{
    GenerateExecutable = true,
    TreatWarningsAsErrors = false,
    CompilerOptions = "/t:winexe",
    IncludeDebugInformation = false,
    OutputAssembly = dlg.FileName,
};


string[] assemblies = {
    "System", "System.Core", "System.Data", "mscorlib",
    "System.Drawing", "System.Windows.Forms", "Microsoft.CSharp",
    @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase",
    @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore",
    @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFrameWork"
};

foreach (string a in assemblies)
{
    p.ReferencedAssemblies.Add(a + ".dll");
}

这工作正常,但您会注意到我必须输入 Windowsbase.dllPresentationCore.dllPresentationFrameWork.dll< 的绝对路径,否则会因为找不到而抛出错误。 这可能不适用于所有计算机。

我能做什么?

(我想我可以在项目文件夹中包含 3 个 .dll 并将它们与应用程序一起发送并引用相对路径(我现在无法测试它是否有效) ,但还有其他方法吗?)

最佳答案

作弊的一种方法是,如果您在项目中引用该 dll,您可以执行以下操作:

typeof(System.Windows.Point).Assembly.Location

这会让您解决 WindowsBase 问题。

关于c# - CodeDom ReferencedAssemblies 绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604344/

相关文章:

c# - Linq to Xml : Is XDocument a caching reader?

.net - XmlSchema.Read 给出 COMException "Catastrophic failure"

c# - 从蛋糕脚本中将警告消息记录在文本文件中

c# - 如何使用 WPF 使 Windows 静音?

c# - 如何修改 KendoUI slider 刻度上的标签?

c# - Silverlight 中的 UrlPathEncode?

C# heapSort ,System.Timers;检查算法时间

c# - 使用 Nuget.VisualStudio 安装 NuGet 包时如何生成绑定(bind)重定向?

c# - 使用程序集共享枚举

wpf - PreviewMouseLeftButtonDown 和 InputBindings 的关系