2

我创建了一个 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());

    }
4

1 回答 1

5

也可以看看

C#:自定义程序集目录

您可以将其他搜索路径添加到您的 app.config,它会在其中查找以加载程序集。例如

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="lib" />
  </assemblyBinding>
</runtime>
于 2012-10-02T14:39:54.737 回答