기존의 애플리케이션이 다른 버전의 CLR로 제작된 경우, 때로는 애플리케이션이 실행될 CLR 버전을 변경시킬 필요가 있다. 이런 경우 애플리케이션의 config 파일에 다음 설정을 추가함으로써 원하는 CLR 버전을 선택할 수 있다.

Forces the v1.0 CLR to be run. If the v1.0 CLR is not installed, the app will fail to run.

<?xml version ="1.0"?>
<configuration>
    <startup>
         <requiredRuntime version="v1.0.3705"/>
         <supportedRuntime version="v1.0.3705"/>
     </startup>
</configuration>

현재 실행되는 어셈블리가, 현재 설치되어 있는 CLR 버전보다 최신 버전에서 개발된 경우에는 "BadImageFormatException" 예외를 발생시킬 수 있다. 자세한 내용은 New Assembly, Old .NET (and Vice-Versa)를 참고한다.

다음은 바인딩시 다른 버전으로 어셈블리 바인딩을 유도하는 설정이다. 바인딩에 대해서는 지난 포스트를 참고한다.

Redirects “assemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=25283151a234958d“ to version 2.0.0.0 of that assembly. This is only useful for strongly-named assemblies, since versions don't matter for those that are simply-named.

<?xml version ="1.0"?>
<configuration>
<runtime>

        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

                <dependentAssembly>
                        <assemblyIdentity name="assemblyName" culture="" publicKeyToken="25283151a234958d"/>
                        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>

                </dependentAssembly>
        </assemblyBinding>

</runtime>
</configuration>

다음은 어셈블리의 코드 베이스값을 변경하는 설정이다.

Redirects “assemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8968ee41e78ce97a“ to codebase “http://www.yourwebsite.com/filename.dll“. 'Href' can also be set to something like “file:///c:/localfile/filename.dll“. Note that redirecting to a codebase causes a System.Net.WebPermission or System.IO.FileIOPermissionAccess.Read + PathDiscovery demand when loading that assembly.

<?xml version ="1.0"?>
<configuration>
<runtime>

        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

                <dependentAssembly>
                        <assemblyIdentity name="assemblyName" culture="" publicKeyToken="8968ee41e78ce97a"/>
                        <codeBase version="1.0.0.0" href="http://www.yourwebsite.com/filename.dll"/>

                </dependentAssembly>
        </assemblyBinding>

</runtime>
</configuration>

다음 내용은 블로그 Suzanne Cook's .NET CLR Notes 의 포스트의 내용을 그대로 옮겨놨다.

Posted by dalbong2