【发布时间】:2012-07-21 04:56:02
【问题描述】:
我正在使用WPF forms 创建一个新的.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 并将它们与应用程序一起发送并引用相对路径(如果它有效,我现在无法测试它),但是还有其他方式?)
【问题讨论】:
-
您确定这些程序集已在 GAC 中注册吗?这可能是他们没有被发现的原因。
-
GAC 是什么意思?在 VS 或 .NET Framework 中没有更改任何内容。
标签: c# .net wpf assemblies codedom