我有一个调用quartz.net的Windows服务,如下所示:
ISchedulerFactory schedFact = new StdSchedulerFactory();
sched = schedFact.GetScheduler();
sched.Start();
我的配置文件如下:
<add key="quartz.plugin.xml.fileNames" value="~/quartz/quartz_jobs.xml" />
在发布我的Windows服务时,我设计了以下文件夹结构:
/bin/ "Various Dlls for my windows service"
/bin/Quartz/ "Includes by schedule plugins ( Seperate classes and my Jobs file )
我遇到的问题是石英找不到我的装配体,除非我将它们复制到/ bin /的根目录中。
如何将所有日程安排程序集保存在单独的文件夹中?
答案 0 :(得分:2)
感谢Google小组的Karell。
这是解决这个问题的代码。
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
private Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
Assembly MyAssembly,objExecutingAssemblies = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
if(args.Name.Contains("Coyname.Product.Service.Scheduler"))
{
string assName = Parser.ParseAssemblyNameReference(args.Name);
var rootDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var pluginDir = Path.Combine(rootDirectory, "Quartz");
pluginDir += string.Format("\\{0}.dll",assName);;
MyAssembly = Assembly.LoadFrom(pluginDir);
}
else
{
MyAssembly = Assembly.LoadFrom(string.Empty);
}
return MyAssembly;
}