我创建了一个mvc 3项目,命名空间是[POC.MVC.PluginHost]。控制器命名空间是[POC.MVC.PluginHost.Controllers]。我创建了一个类库项目,并将其名称空间更改为[POC.MVC.PluginHost.Controllers]。
类库项目代码:
namespace POC.MVC.PluginHost.Controllers
{
public class BasicExampleController : Controller
{
public ActionResult Index()
{
// Add action logic here
throw new NotImplementedException();
}
public ActionResult Display()
{
return Content("");
}
}
}
我编译它并复制到mvc项目的bin目录,当我浏览http://localhost:xxxx/BasicExample/display
它工作正常,但我想将这个已编译的类库的dll复制到像[plugin]这样的其他文件夹中,但它不是工作,只有当我将它复制到我的mvc项目的bin文件夹时它才有效。有没有办法解决这个问题?
编辑.....................................
我在我的web.config中测试,如:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Plugin" />
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
但这不起作用!!!!
我测试了这个但是这仍然不起作用.....
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string assembliesDir = "Plugin";
string aa = System.IO.Path.Combine(assembliesDir, args.Name + ".dll");
aa = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, aa);
Assembly asm = Assembly.LoadFrom(aa);
return asm;
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
AppDomain.CurrentDomain.Load("SamplePlg");
System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new AssemblyResourceProvider());
}
答案 0 :(得分:5)
您可以向app.config添加其他搜索路径,以便加载程序集。例如
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>