In the world of Visual Studio programming, we all must be dealing with multiple projects in a solution. Multiple projects in a solution has become a business need in today’s programming world. We have moved towards multi-tiered architecture where each tier is a project in itself.
So a solution where we have multiple projects, we also have to maintain assembly versions to track the current version in production. Maintaining assembly versions for all projects becomes a pain when we have to manually modify the version for each and every project in the solution. A developer may miss modifying the assembly version of a project which may result in inconsistency and confusion with the version of product or project in production. The scenario may not occur where there are specific teams for deployment, but is a common issue with teams with small sizes where a developer has to play multiple roles starting from analysis, development, testing and deployment.
To eradicate possibility of such errors, in visual studio we have a concept of linked files. The concept of linked files can be applied practically to “Shared Assembly Info”. A Shared assembly info file is a normal file same as our AssemblyInfo.cs or AssemblyInfo.vb file and contains attributes that will be shared across projects in a particular solution.
In order to implement the Shared Assembly Info functionality, create a normal cs or vb file in your solution and name it as SharedAssemblyInfo.cs or SharedAssemblyInfo.vb in your solution folder. Now add this file as a link file in all the projects in that solution. In order to add this as a linked file, follow the steps below:
- Right click on the project, in which you wish to add the Shared assembly file, and select Add -> Existing Item...
- Select the file “SharedAssemblyInfo.cs” from the solution folder.
- Instead of Add, click on the the arrow next to Add and click “Add as Link”
- Drag down the added linked file alongside AssemblyInfo.cs in the same folder.
- Repeat steps 1 – 4 for all projects for which you wish to add shared assembly file.
After adding links to shared assembly info, your solution explorer would look like
You are now ready to modify the SharedAssemblyInfo.cs file to add attributes common across the solution. I would prefer having my SharedAssemblyInfo.cs file as
My AssemblyInfo.cs file for a project would now look something like:
In order to maintain same assembly version across projects, we now just need to modify the SharedAssemblyInfo.cs file and the version would be reflected across projects.
Hope this helps.