如何避免加载不合规的程序集

ASP.NET .NET 4.6 MVC4应用程序加载了unnessecary assemblie,eq。 System.Data.OracleClient。 没有使用Oracle。

使用控制器中的代码创建程序集依赖项

var sb = new StringBuilder(); foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies()) { sb.AppendLine(b.FullName); foreach (AssemblyName an in b.GetReferencedAssemblies()) sb.AppendLine(" " + an.Name); } 

输出低于。 根据此System.Web引用System.Design和System.Design对System.Data.OracleClient的引用

MVC应用程序在内存有限的VPS服务器中运行。 如何解决这个问题,以便不加载unnessecary程序集? 这有望在VPS服务器中释放一些内存。

 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a mscorlib System.Drawing System System.Configuration System.Core System.Data System.Xml System.DirectoryServices System.EnterpriseServices System.Web.RegularExpressions System.Design System.Web.ApplicationServices System.ComponentModel.DataAnnotations System.DirectoryServices.Protocols System.Security System.Runtime.Caching System.ServiceProcess System.Web.Services Microsoft.Build.Utilities.v4.0 Microsoft.Build.Framework Microsoft.Build.Tasks.v4.0 System.Windows.Forms System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 mscorlib System.Configuration System.Xml System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 mscorlib System System.Xml System.Numerics System.Security System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 mscorlib System System.Configuration System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a mscorlib System System.Xml System.Security System.Core System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 mscorlib System System.Data.SqlXml System.Configuration System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a mscorlib System System.Data System.Configuration Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a mscorlib Microsoft.Build.Framework System System.Xml System.Core ... System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 mscorlib System.Configuration System.Data System.Transactions System System.EnterpriseServices 

web.config绑定部分也不包含它:

                                      

更新

我试着根据回答将删除命令放到web.config但是得到了错误

在此处输入图像描述

还试图根据答案使用删除oracle部分

   
...

但得到了错误:

在此处输入图像描述

怎么解决?

Web应用程序上有三种程序集。

  1. 与您使用的库(dll)一起组装的程序集
  2. 作为Web应用程序的已编译版本的程序集
  3. 主要运行站点的程序集

图书馆

在前一种情况下,您可以优化您的库 ,直接在您的dll项目中删除任何不必要的引用。

参考

在第二种情况下优化你的网页和编译什么你需要删除任何不必要的代码背后的代码…例如页面通常有这第一行

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; 

而你不使用的是灰色,你可以删除它…

网络集会

而现在困难的部分 – 很难,因为你必须玩“尝试/失败”游戏。 现在你可以删除和从哪里删除。

首先我在哪里搜索以找到要删除的内容…答案是在asp.net上的全局web.config上。 在我的情况下,我转到Windows目录,在我的curent框架版本上,在config目录中找到web.config

在那里我找到了一些钥匙….

首先,您可以在web.config上的httpModule会话中删除不必要的Http模块以获得更快的管道

这是我在全球web.config上看到的

                 

我在我的应用程序上转到web.config,这就是我删除我不使用的内容:

      

现在为你的情况我继续汇编会话,这是我在全球web.config上看到的:

                                 

这是我复制/粘贴到我的web.config并在第一行放置然后我开始删除我知道我的程序不使用的行…并小心保持这一行最后,这表示从dll目录添加库。

       ....   

通过删除并查看您的应用程序是否仍在工作,制作此文件并删除您不使用的文件,可以限制您使用的程序集。

我做了一个简单的测试并删除了这一行

  

这次我只计算从83下降到79只assembly件。 为什么不止一个减去? 因为WorkflowServices加载了更多。

要从配置部分删除某些内容,请再次在web.config上执行以下操作:

    ... 

我工作的工作站在整个machine.config中都引用了Oracle。 我相信你会在那里找到你的流氓参考。

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config