以 .NET Framework 版本為目標
您可以使用應用程式組態檔指定應用程式或元件支援的 .NET Framework 版本。當您在應用程式組態檔中使用 <supportedRuntime> 和 <requiredRuntime> 項目時,應指定每個受支援 .NET Framework 版本的版本和組建編號。
指定應用程式可以使用哪一個 .NET Framework 版本的設定規則,在 .NET Framework 1.1 中更為嚴格。若是使用 .NET Framework 1.0 版的應用程式,無論組態檔指定了什麼,這個應用程式都會在 .NET Framework 1.0 版上執行。若是使用 .NET Framework 1.1 版的應用程式,應該使用 <supportedRuntime> 項目指定應用程式支援哪個 (或哪些) Runtime 版本。注意:除非特別經過設定,否則用 .NET Framework 1.0 版建置的應用程式會自動配合 .NET Framework 1.1 版執行。
**注意 **應用程式組態檔的名稱必須與應用程式相同,再加上 .config 副檔名。例如,如果應用程式名為 myExecutable.exe,則必須將應用程式組態檔命名為 myExecutable.exe.config。
目前,您可以將應用程式指定成在 .NET Framework 1.0 版、.NET Framework 1.1 版或兩者上執行。
對準 .NET Framework 1.1 版
在下列情況中,本章節顯示的應用程式組態檔項目會造成使用 .NET Framework 1.0 版建置的應用程式用 .NET Framework 1.1 版:
- 如果安裝了 .NET Framework 1.1 版。
- 如果同時安裝了 .NET Framework 1.0 和 .NET Framework 1.1 兩個版本。
如果只有安裝 1.0 版,應用程式仍會執行,因為 1.0 版並不識別 <supportedRuntime> 項目,並且使用在指向 1.0 版之 PE 標頭檔中的版本。
下圖中,MyApp 和組件 A 具有 .NET Framework 1.0 版的靜態參考,而組件 B 則有 .NET Framework 1.1 版的靜態參考。在這個範例中,MyApp 的應用程式組態檔指出該應用程式支援 1.1 版,因此應用程式和組件 A 被重新導向成使用 .NET Framework 1.1 版。
將組件繫結重新導向至1.1 版的應用程式組態檔
若要以使用 .NET Framework 1.0 版的應用程式為目標,以便在 .NET Framework 1.1 上執行
在應用程式組態檔中輸入下列 XML:
<?xml version ="1.0"?> <configuration> <startup> <supportedRuntime version="v1.1.4322" /> </startup> </configuration>
對準 .NET Framework 1.0 版
將使用 .NET Framework 1.1 版建置的應用程式指定成在 .NET Framework 1.0 版上執行時,在應用程式組態檔中就需要較大的項目。構成 .NET Framework 的每一個組件都必須重新導向成使用 .NET Framework 1.0 版。
在下列情況中,本章節中顯示的應用程式組態檔項目會讓應用程式使用 .NET Framework 1.0 版:
- 如果安裝了 .NET Framework 1.0 版。
- 如果同時安裝了 .NET Framework 1.0 和 .NET Framework 1.1 兩個版本。
如果只安裝 .NET Framework 1.1 版,該應用程式便無法執行。
下圖中,MyApp 和組件 A 具有 .NET Framework 1.0 版的靜態參考,而組件 B 則有 .NET Framework 1.1 版的靜態參考。在這個範例中,MyApp 的應用程式組態檔指出該應用程式支援 1.0 版,因此組件 B 被重新導向成使用 .NET Framework 1.0 版。
將組件繫結重新導向至1.0 版的應用程式組態檔
若要以使用 .NET Framework 1.1 版的應用程式為目標,以便在 .NET Framework 1.0 上執行
在應用程式組態檔中輸入下列 XML:
<?xml version ="1.0"?> <configuration> <startup> <requiredRuntime version="v1.0.3705" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705"> <dependentAssembly> <assemblyIdentity name="Regcode" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.EnterpriseServices" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Security" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="CustomMarshalers" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Accessibility" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Configuration.Install" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.DirectoryServices" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Drawing.Design" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.ServiceProcess" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.RegularExpressions" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Services" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Windows.Forms" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Design" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Messaging" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="IEExecRemote" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="IEHost" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="IIEHost" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="ISymWrapper" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="mscorcfg" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Management" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime.Remoting" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime.Serialization.Formatters.Soap" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mobile" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Vsa.Vb.CodeDOMProcessor" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft_VsaVb" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Vsa" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.VisualBasic.Vsa" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="cscompmgd" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.JScript" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.VisualBasic" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.VisualC" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="7.0.3300.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>