meh*_*r4n 2 .net c# asp.net-mvc asp.net-mvc-3
我创建了一个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("");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我编译它并复制到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>
Run Code Online (Sandbox Code Playgroud)
但这不行!!!!
我测试这个但是这仍然不起作用.....
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());
}
Run Code Online (Sandbox Code Playgroud)
您可以向app.config添加其他搜索路径,以便加载程序集.例如
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)