本节讲解如何使用程序集内嵌的资源,先看我的程序集
ok,假如我要发布这个网站,我又不想让别人看到xml文件的内容,那么我们就把xml设置成内嵌(build action 设置成Embedded Resource),copy to output directry设置成dont't copy。我现在要使用内嵌的Nhibernate.cfg.xml。代码如下:
//private string xmlPath = AppDomain.CurrentDomain.BaseDirectory + @"bin\Nhibernate.cfg.xml"; 
Configuration cfg =
null;
public DaoHelper()

{
//cfg = new Configuration().Configure(xmlPath); 
Assembly bl = Assembly.GetAssembly(
typeof(SpringDao.SpringContext));

cfg =
new Configuration().Configure(bl,
"SpringDao.Nhibernate.cfg.xml");

}
ok,这样就通过内嵌的xml对Configuration进行了配置。
AppDomain.CurrentDomain.BaseDirectory指的是webConfig所在的目录。