What is the Assembly Information File for in C# and how do I use it?
The AssemblyInfo file is used to document your dlls or exes to describe where the code comes from, its version etc. If your code is publicly available then its certainly good practice to make sure you add useful information too it.
http://www.codinghorror.com/blog/archives/000141.html
If you build your project with NAnt there is also a useful target that allows you to build the assembly info dynamically.
http://nant.sourceforge.net/release/latest/help/tasks/asminfo.html
Right-click on any program icon, and select 'Properties'. Navigate to the 'Version' tab. That information you see is what is contained in the AssemblyInfo.cs file, among other things.
It holds information about your assembly. Author, Company, Version Numbers (build/minor/major/etc)
Try this article:
http://msdn.microsoft.com/en-us/library/1h52t681.aspx
It's a file created by the default project templates under the "Properties" folder that has attributes defined at the assembly-level that the C# compiler and framework use to store various bits of metadata like the title of the assembly, the version, the publisher, etc. There's other framework-specific attributes that you can throw in there such as XAML namespaces, Data Contract namespaces, etc. Basically any attributes that you define at the assembly level are typically placed in here.
There's nothing special about the name though. These attributes can actually appear anywhere in any code file.
I posted a neat little tip about dealing with the issue of having multiple AssemblyInfo files in different projects in a solution that all have common attributes.
Related
Basically, I developped a small library with some common fonctionnalities that I use in all my projects. For some political reasons, I cannot choose a generic name for that library (including namespace and assembly name). Usually, it must include the name of the enterprise, something like this for the namespace: Enterprise.ProjectName.XXX.YYY.
For the moment, I'm doing a copy of my library, then I'm renaming the namespaces manually with Visual Studio, and finally I'm recompiling the whole thing.
So my question is the following: Is it possible to create a small program that takes an assembly as input, rename all namespaces from MyLibrary.XXX.YYY to Enterprise.ProjectName.XXX.YYY as well as the assembly name?
What are the steps to follow?
[Edit]
Generating the assembly automatically seems to much work. I will use resharper and/or CTRL+ALT+F like I did so far. Thanks for the answers...
You could use Mono's Cecil project to disassemble the assembly, inspect each type, rename or recreate the type with a new namespace, and generate the resulting assembly.
That being said, it might be simpler to use a tool like Resharper which allows you to rename namespaces correctly within the code base.
Some options:
If you are copying the entire source code for your library into your new project, you can use a refactoring tool like Resharper to "Adjust Namespaces". This is a pretty quick and safe refactoring.
If you just need to avoid shipping the internally named assembly, you may be able to use ILMerge to 'hide' the internal assembly during a post-build step. This is viable if it's just a perception issue for the final assembly names in the binary output directory.
Deal with the issue at the political level by describing your internal library as being no different from any other third-party dependency. Then the naming is no longer a problem. This may solve other problems if you're shipping the source code of this library to multiple clients, as it clarifies that you are not giving full ownership of your 'shared' code to each client. Otherwise they could potentially argue that you are not allowed to use that 'shared' code in projects for other clients, since it is clearly owned by them, having their enterprise name in the namespace.
I read a lot about changing the metadata of music or images, but what about normal executable? How do I edit the comment / title of them? I am using .NET 2
You can specify various bits of metadata about a .NET assembly by simply including assembly attributes like so:
<Assembly: AssemblyTitle("ConsoleApplication9")>
<Assembly: AssemblyDescription("Blah")>
<Assembly: AssemblyCompany("My Company")>
<Assembly: AssemblyProduct("ConsoleApplication9")>
<Assembly: AssemblyCopyright("Copyright © My Company 2012")>
<Assembly: AssemblyTrademark("")>
Normally you place these in a file called AssemblyInfo.vb and compile it into your assembly (Visual Studio will generate this for you from the settings you set if you go to project settings - Application | Assembly Information. Have a look in the project folder, there is by default a sub-folder with the same name as your project and in there is the aforementioned .vb file).
If you want, however, to update a precompiled .NET assembly I think you would need to decompile it, change the attributes in the manifest you want to change and re-compile it. You can do this using the ildasm tool. If an assembly is strong named you will not be able to recompile it using the same strong name than it was compiled with of course.
Properties like comment or title are not provided for all files equally, because they are not stored by the filesystem but come from the file itself. Therefore they must be part of the file format and not all file formats provide such properties. Indeed, many file formats don't provide any properties at all (e.g. .txt). Even when the file format supports some properties, Windows needs a custom property handler installed to extract, interpret and possibly modify them.
Executables provide some read-only properties through the version information resource. However they cannot and should not be changed, because this will mess up file checksums, break digital signatures etc.
Is it normal I can't see xml comments from external libraries?
For example I have an external library with xml comments on methods. After making a reference to this library I was hoping that xml comments appears when I make usage of the external library; But nothing appear in the tooltip :
Maybe I have to do something special when I make the build of the lib.
First you need to enabled "XML File Documentation" generation. You can find it in the Settings of the Project under the section Build.
Then will the compiler generate an XML File containing your documentation of the assembly on build.
If you reference the assembly in another project and you want to see the documentation of types, methods, etc. in IntelliSense you need to store the xml documentation file in the same folder, where the referenced assembly is stored.
Following on from my previous question, what useful information can you retrieve from a .net assembly about the build process? I know I can look at the AssemblyVersion to get major and minor application version, and when the build took place.
Can I find:
Who did the build? i.e. user name.
On what machine?
Which O/S version?
Anything else useful?
From my (limited) investigations (into assemblies I've built) you're basically limited to what the author put into the file.
About the only thing that's automatically assigned are the "Internal Name", "Original File name" and "Language".
There might be some IDE's that put in the information you require, but by default Visual Studio isn't one of them.
By default, you don't have any of that information. Jon's answer to your previous question is actually the correct way to do this. You want to create custom attributes for each piece of information you want (or one attribute with properties for each) that apply to an assembly. This is how the attributes typically found in your AssemblyInfo file work.
Is there a way to make assembly attributes show up when you right click-> Properties->details on an exe?
I know about the standard ones but I want to add my own (e.g. Email).
Edit: Also if there is a way to do this post build, that would be fine.
The information on the Version tab is retrieved from the executable's VERSIONINFO resource (we're talking native Win32 resources here, not managed resources). By default the compiler will take information from some of the Assembly attributes and put into the VERSIONINFO resource. Unfortunately you can't change which attributes the compiler uses here, so you can't include your own information this way.
But if you really want you can create your own VERSIONINFO resource and put in a .RES file and embed in your executable using the Csc.exe /win32res compiler option.
Haven't seen a pure .NET solution, but perhaps you could you combine this with this?