我正在用 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.dll
、PresentationCore.dll
和 PresentationFrameWork.dll< 的绝对路径
,否则会因为找不到而抛出错误。
这可能不适用于所有计算机。
我能做什么?
(我想我可以在项目文件夹中包含 3 个 .dll
并将它们与应用程序一起发送并引用相对路径(我现在无法测试它是否有效) ,但还有其他方法吗?)
最佳答案
作弊的一种方法是,如果您在项目中引用该 dll,您可以执行以下操作:
typeof(System.Windows.Point).Assembly.Location
这会让您解决 WindowsBase 问题。
关于c# - CodeDom ReferencedAssemblies 绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604344/