如何避免加载不必要的程序集 [英] How to avoid loading unnessecary assemblies

查看:35
本文介绍了如何避免加载不必要的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET .NET 4.6 MVC4 应用程序加载不必要的程序集,等式.System.Data.OracleClient .未使用 Oracle.

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

 var sb = new StringBuilder();foreach(AppDomain.CurrentDomain.GetAssemblies() 中的程序集 b){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 服务器中运行.如何解决这个问题,以便不加载不必要的程序集?这有望释放 VPS 服务器中的一些内存.

mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089System.Web,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3amscorlib系统图系统系统配置系统核心系统数据系统文件系统.目录服务系统.企业服务System.Web.RegularExpressions系统设计系统.Web.应用服务System.ComponentModel.DataAnnotations系统.目录服务.协议系统安全系统.运行时.缓存系统.服务进程系统.网络.服务Microsoft.Build.Utilities.v4.0Microsoft.Build.FrameworkMicrosoft.Build.Tasks.v4.0系统.Windows.Forms系统,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089mscorlib系统配置系统文件System.Core,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089mscorlib系统系统文件系统.数值系统安全System.Web.ApplicationServices,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35mscorlib系统系统配置System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3amscorlib系统系统文件系统安全系统核心System.Xml,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089mscorlib系统系统.Data.SqlXML系统配置System.Runtime.Caching,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3amscorlib系统系统数据系统配置Microsoft.Build.Utilities.v4.0,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3amscorlibMicrosoft.Build.Framework系统系统文件系统核心...System.Data.OracleClient,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089mscorlib系统配置系统数据系统事务系统系统.企业服务

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

 <运行时><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><从属程序集><assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/></dependentAssembly><从属程序集><assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/></dependentAssembly><从属程序集><assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/><bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/></dependentAssembly><从属程序集><assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/><bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/></dependentAssembly><从属程序集><assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/><bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/></dependentAssembly><从属程序集><assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/></dependentAssembly><从属程序集><assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/></dependentAssembly><从属程序集><assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/></dependentAssembly></assemblyBinding></运行时>

更新

我尝试根据答案将删除命令放置到 web.config 但出现错误

还尝试根据答案使用

删除oracle部分<预><代码><配置><configSections><section name="system.data.oracleclient" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><remove name="system.data.oracleclient"></remove></节></configSections>...

但出现错误:

如何解决?

解决方案

Web 应用程序中包含三种程序集.

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

图书馆

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

参考

在第二种情况下,要优化您的网页以及要编译的内容,您需要删除对背后代码的任何不必要的引用……例如页面通常有第一行

使用系统;使用 System.Collections.Generic;使用 System.IO;使用 System.Linq;使用 System.Web;使用 System.Web.UI;使用 System.Web.UI.WebControls;

你不用的都是灰色的,可以去掉...

网络程序集

现在是困难的部分 - 困难,因为您必须玩尝试/失败"游戏.现在你可以删除什么以及从哪里删除.

首先我在哪里搜索以找到要删除的内容...答案就在 asp.net 上的全局 web.config 上.在我的情况下,我转到 windows 目录,在我当前的框架版本上,在 config 目录上,找到 web.config

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

首先,您可以在 web.config

上的 httpModule 会话中删除不必要的 Http 模块以加快管道速度

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

<add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/><add name="Session" type="System.Web.SessionState.SessionStateModule"/><add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/><add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/><add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/><add name="RoleManager" type="System.Web.Security.RoleManagerModule"/><add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/><add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/><add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule"/><add name="Profile" type="System.Web.Profile.ProfileModule"/><add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule"/><add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></httpModules>

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

<删除名称=会话"/><remove name="PassportAuthentication"/><remove name="AnonymousIdentification"/></httpModules>

现在对于你的情况,我继续进行程序集会话,这是我在全局 web.config 上看到的:

<编译><组件><remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="mscorlib"/><add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><add assembly="*"/><add assembly="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></组件>

这是我复制/粘贴到我的 web.config 并将 <clear/> 放在第一行然后我开始删除我知道我的程序没有使用的行... 并小心保留这一行 <add assembly="*"/> 最后,这表示要从 dll 目录中添加您的库.

 <程序集><清除/><add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/><add assembly="mscorlib"/><add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>....<add assembly="*"/></组件>

制作并删除您不使用的那个,通过删除并查看您的应用程序是否仍在工作,您可以限制您使用的程序集.

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

<add assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

我这次从 83 个只加载了 79 个程序集.为什么减去一个以上?因为 WorkflowServices 自己加载了一些.

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

<预><代码><配置><configSections><remove name="system.data.oracleclient"></remove>...

ASP.NET .NET 4.6 MVC4 application loads unnessecary assemblie, eq. System.Data.OracleClient . Oracle is not used.

Assembly dependencies are created using code in controller

        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);
        }

Output is below. According to this System.Web references to System.Design and System.Design references to System.Data.OracleClient

MVC Application is running in VPS server with limited memory. How to fix this so that unnessecary assemblies are not loaded? This will hopefully free some memory in VPS server.

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 binding section does not also contain it:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Update

I tried according to answer to place remove command to web.config but got error

Also tried to remove oracle section according to answer using

<configuration>
  <configSections>
    <section name="system.data.oracleclient" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <remove name="system.data.oracleclient"></remove>
    </section>
  </configSections>
  ...

but got error:

How to fix it ?

解决方案

There are three kind of assemblies on a web application.

  1. assemblies that are come together with the libraries (dlls) that you use
  2. assemblies that are the compiled version of your web application
  3. assemblies that are main to run the site

Libraries

In the first one case, you can optimize yours libraries, removing any unnecessary reference direct on the project of your dll.

Reference

In the second case to optimize your web page and what to compile you need to remove any unnecessary reference on the code behind... eg page usually have this first lines

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

and what you do not use there are gray, you can remove it...

web assemblies

And now the difficult part - difficult because you must play the "try/fail" game. Now what you can remove and from where.

First where to I search to find what to remove... and the answer is on global web.config on asp.net. In my case I go to windows directory, on my curent framework version, on config directory and find the web.config

There I locate some keys....

First you can remove unnecessary Http Modules for faster pipeline in the httpModulesession on web.config

This is what I see on global web.config

<httpModules>
    <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
    <add name="Session" type="System.Web.SessionState.SessionStateModule" />
    <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
    <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
    <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
    <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
    <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
    <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
    <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
    <add name="Profile" type="System.Web.Profile.ProfileModule" />
    <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
    <add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

and I go to web.config on my application and this is how I remove what I am not use:

<httpModules>
  <remove name="Session" />
  <remove name="PassportAuthentication" />
  <remove name="AnonymousIdentification" />
</httpModules>

Now for you case I continue on assemblies session, this is what I see on global web.config:

<compilation>
        <assemblies>
            <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="mscorlib" />
            <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add assembly="System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="*" />
            <add assembly="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </assemblies>

this as it is I copy/paste to my web.config and place <clear /> on first line then I start remove the lines that I KNOW that my program is not use... and be careful to keep this line <add assembly="*" /> and at the end, this says to add your library from your dll directory.

            <assemblies>
                <clear />
                <add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                <add assembly="mscorlib" />
                <add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
....
                <add assembly="*" />
            </assemblies>

Making this and removing the one that you not use, by remove and see if your application is still working, you can limit a lot the assemblies that you use.

I make a simple test and by removing this line

<add assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

I count from 83 down to 79 only assemblies loaded this time. Why more than one minus ? because WorkflowServices loads some more by them self.

To remove something from configuration section, again on your web.config you do it as:

<configuration> 
  <configSections>
        <remove name="system.data.oracleclient"></remove>
...

这篇关于如何避免加载不必要的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆