DEV343.NET Application and Library Versioning Juval Löwy .

33
DEV343 .NET Application and Library Versioning Juval Löwy www.idesign.net

Transcript of DEV343.NET Application and Library Versioning Juval Löwy .

Page 1: DEV343.NET Application and Library Versioning Juval Löwy .

DEV343

.NET Application and Library VersioningJuval Löwy

www.idesign.net

Page 2: DEV343.NET Application and Library Versioning Juval Löwy .

Software architectFormer corporate architect of a Fortune 500 company

Consults on .NET migration and design

MS Regional Director for the Silicon Valley

Participates in .NET design reviews

AuthoredProgramming .NET Components (2003, O’Reilly)

COM and .NET Component Services (2001, O’Reilly)

Contributing editor and columnist to several magazines

Contact at www.idesign.net

About Juval Löwy

Page 3: DEV343.NET Application and Library Versioning Juval Löwy .

Outline

Sharing and versioning

Side-by-side execution

Custom version policies

CLR versioning

Page 4: DEV343.NET Application and Library Versioning Juval Löwy .

Shared Assemblies

Assemblies can be private or shared

A private assembly resides in the app directory

A shared assembly is in a known location, called the global assembly cache (GAC)

Shared assembly used for:

Sharing

Side-by-side execution

Page 5: DEV343.NET Application and Library Versioning Juval Löwy .

Shared Assemblies

Shared assemblies must have a unique name

Called Strong Name

Strong name authenticates assembly’s origin and identity

Shared assembly implies trust

Strong name cannot be generated by a party other than the original publisher

Strong name is based on public/private keys pair

Page 6: DEV343.NET Application and Library Versioning Juval Löwy .

Shared Assemblies

Digitally signs the assembly to verify originEncrypt manifest using the private key Append signature to manifest Incorporated public key into the assembly

To verify authenticity .NET loader generates the hashDecrypts the manifest-stored hashCompare

Can only call signed assembly from within signed assemblies

Page 7: DEV343.NET Application and Library Versioning Juval Löwy .

[assembly: AssemblyKeyFile("MyAssembly.snk")]

Shared Assemblies

To generate keys pair:sn.exe –k MyAssembly.snk

Add the snk file to assembly info file:

Installing in the GACDrag and drop

.NET configuration tool

gacutil –i MyAssembly.dll

Page 8: DEV343.NET Application and Library Versioning Juval Löwy .

Shared Assemblies

You need to reference assembly to build the client

But not to deploy it

Page 9: DEV343.NET Application and Library Versioning Juval Löwy .

Shared Assemblies

Disable client local copy of a shared assembly

Set to False automatically if in the GAC already, and not added usingthe Projects tab

Side-by-SideDemo

Page 10: DEV343.NET Application and Library Versioning Juval Löwy .

Versioning

Assemblies are not necessarily backward-compatibleEach client assembly records in manifest exact version of ot5her server assemblies

.NET resolves compatibility at runtimeVersion number is the product of:

Major,Minor,Build,RevisionRecorded as assembly attribute

[assembly: AssemblyVersion("2.1.1524.1")]

Major Minor Build Revision

Page 11: DEV343.NET Application and Library Versioning Juval Löwy .

Either explicitly specify version numbers, or rely on compiler

What is not specified is zeroed

If you provide major & minor, can * build and revision

Build is number of days since January 1, 2000, LIMA

Revision is half number of seconds since midnight, LIMA[assembly: AssemblyVersion("2")]

[assembly: AssemblyVersion("2.1")][assembly: AssemblyVersion("2.1.*")]//best[assembly: AssemblyVersion("2.1.1524")][assembly: AssemblyVersion("2.1.1524.*")]

Versioning

Page 12: DEV343.NET Application and Library Versioning Juval Löwy .

Resolving Version

When trying to use a shared assemblyPossible many versions of the same assembly in the GAC

Client always gets assembly with exact version match

Can provide custom policy

Developers must be disciplinedRelease procedures

Page 13: DEV343.NET Application and Library Versioning Juval Löwy .

Resolving Version

Private assembly can be strongly named

.NET ignores version of private assemblies with friendly name only

.NET enforces version compatibility of private assembly with strong name

Page 14: DEV343.NET Application and Library Versioning Juval Löwy .

Resolving Version

ConclusionsPrivate assemblies with only friendly names must be backward compatible

Private assemblies with strong name may not be backward compatible

Even if a private assemblies with strong name is backward compatible (content wise), if the version number is not compatible, it may result in an exception

Private assembly deployment model is really intended to work with friendly names only

Page 15: DEV343.NET Application and Library Versioning Juval Löwy .

Custom Version Policy

Application can provide version binding policy

Override default policy

For shared and private assemblies

Can deploy machine-wide policy

.NET configuration toolMMC snap-in

Page 16: DEV343.NET Application and Library Versioning Juval Löwy .

Custom Version Binding

Binding policy:

Page 17: DEV343.NET Application and Library Versioning Juval Löwy .

Custom Version Binding

Codebase policy:Redirect to new location

Page 18: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

.NET rigorous version computability enforcement makes CLR versioning an interesting problem

Different set of ground rules for CLR versioning

CLR version used depends on:What the app is built with

Available .NET versions

Application CLR versioning policy

Page 19: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

CLR and application frameworks assemblies treated as one versioning unit

Avoid mix-and-match

Intend to be backward compatible, but not forward

Developers must test and certify support for each CLR version

Page 20: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

CLR Side-By Side execution Multiple CLR versions on same machine

Can install and uninstall versions separately

Page 21: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

Version unificationHost process uses single CLR version

.NET always runs unified stack of framework assemblies

EXE application assembly and class libraries it loads use same CLR version

Application select CLR and application frameworks version

Class libraries have no say

Page 22: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

Default CLR version resolution.NET detects version app compiled with

Loads latest compatible CLR version on machine

Compatibility list maintained in Registry

Can lead to undetermined results

Page 23: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

Applications that rely on default typically mainstream applications

Use subset of types and services supported by all CLR versions

Implicitly stating any compatible CLR version is allowed

Page 24: DEV343.NET Application and Library Versioning Juval Löwy .

Specifying supported CLR versions in config file

For deterministic results

In order of priority

<?xml version="1.0"?><configuration> <startup> <supportedRuntime version="v1.1.5000.0"/> <supportedRuntime version="v1.0.3300.0"/> </startup> </configuration>

CLR Versioning

Page 25: DEV343.NET Application and Library Versioning Juval Löwy .

If no supported version is found, .NET refuses to load

CLR Versioning

Page 26: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

Can specify supported runtime at project setting

Page 27: DEV343.NET Application and Library Versioning Juval Löwy .

CLR Versioning

Can specify supported runtime at project setting

Page 28: DEV343.NET Application and Library Versioning Juval Löwy .

More at TechEd

C# Best Practices Day July 01

Distributed Security PracticesDay July 02

Building High-Performance Applications with Visual Studio .NET

Day July 03

Application and Library VersioningDay July 03

Software Legends Friday July 04

Page 29: DEV343.NET Application and Library Versioning Juval Löwy .

ResourcesResourcesProgramming .NET components

By Juval Lowy, O'Reilly April 2003

www.idesign.net

.NET Master Class3-4 annually

Upcoming events onwww.idesign.net

Page 30: DEV343.NET Application and Library Versioning Juval Löwy .

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

Page 31: DEV343.NET Application and Library Versioning Juval Löwy .

evaluationsevaluations

Page 32: DEV343.NET Application and Library Versioning Juval Löwy .

SOFTWARE LEGENDSOFTWARE LEGENDJuval LowyJuval Lowy

THURSDAY 3rd JULY at 16.15-16.45 hrs

Meet the Author’sMeet the Author’s Book signingBook signing

Page 33: DEV343.NET Application and Library Versioning Juval Löwy .

© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.