O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Naming

By default, when you create a new assembly—either a program or a library—its name is based on the filename, but with the file extension stripped. This means that our two example projects in this chapter build assemblies whose filenames are MyProgram.exe and MyLibrary.dll. But as far as the .NET Framework is concerned, their names are MyProgram and MyLibrary, respectively, which is why Example 15-9 just specified MyProgram, and not MyProgram.exe.

Actually, that’s not the whole truth. These are the simple names, but there’s more to assembly names. We can ask the .NET Framework to show us the full name of a type’s containing assembly, using the code in Example 15-10.

Example 15-10. Getting a type’s containing assembly’s name

Console.WriteLine(typeof(MyType).Assembly.FullName);

Running this produces the following output:

MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

As you can see, there are four parts to an assembly name. First there is the simple name, but this is followed by a version number. Assemblies always have a version number. If you don’t specify one, the compiler sets it to 0.0.0.0. But Visual Studio puts an assembly-level attribute in the AssemblyInfo.cs file setting it to 1.0.0.0, which is why we see that in the output. You would typically change the version each time you formally release your code. Example 15-11 shows the (unsurprising) syntax for the version attribute.

Example 15-11. Setting an assembly’s version

[assembly: AssemblyVersion("1.2.0.7")] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required