<p>I have a solution with multiple project. I am trying to optimize AssemblyInfo.cs files by linking one solution wide assembly info file. What are the best practices for doing this? Which attributes should be in solution wide file and which are project/assembly specific?</p>

<hr>

<p><em>Edit: If you are interested there is a follow up question <a href="https://stackoverflow.com/questions/64602/what-are-differences-between-assemblyversion-assemblyfileversion-and-assemblyin">What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?</a></em></p>

[{'answer_id': 62631, 'author': 'SaguiItay', 'author_id': 6980, 'author_profile': 'https://Stackoverflow.com/users/6980', 'pm_score': 0, 'selected': False, 'text': '<p>Using a single AseemblyInfo.cs file for multiple projects is not recommended.\nThe AssemblyInfo file includes information that might be relevant only for that specific assembly. The two most obvious pieces of information are the <code>AssemblyTitle</code> and <code>AssemblyVersion</code>.</p>\n\n<p>A better solution might be to use <code>targets</code> file, which are handled by the MSBuild, in order to "inject" assembly attributes to more than one project.</p>\n'}, {'answer_id': 62637, 'author': 'JRoppert', 'author_id': 6777, 'author_profile': 'https://Stackoverflow.com/users/6777', 'pm_score': 9, 'selected': True, 'text': '<p>We\'re using a global file called GlobalAssemblyInfo.cs and a local one called AssemblyInfo.cs. The global file contains the following attributes:</p>\n\n<pre><code> [assembly: AssemblyProduct("Your Product Name")]\n\n [assembly: AssemblyCompany("Your Company")]\n [assembly: AssemblyCopyright("Copyright © 2008 ...")]\n [assembly: AssemblyTrademark("Your Trademark - if applicable")]\n\n #if DEBUG\n [assembly: AssemblyConfiguration("Debug")]\n #else\n [assembly: AssemblyConfiguration("Release")]\n #endif\n\n [assembly: AssemblyVersion("This is set by build process")]\n [assembly: AssemblyFileVersion("This is set by build process")]\n</code></pre>\n\n<p>The local AssemblyInfo.cs contains the following attributes:</p>\n\n<pre><code> [assembly: AssemblyTitle("Your assembly title")]\n [assembly: AssemblyDescription("Your assembly description")]\n [assembly: AssemblyCulture("The culture - if not neutral")]\n\n [assembly: ComVisible(true/false)]\n\n // unique id per assembly\n [assembly: Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]\n</code></pre>\n\n<p>You can add the GlobalAssemblyInfo.cs using the following procedure:</p>\n\n<ul>\n<li>Select <strong>Add/Existing Item...</strong> in the context menu of the project</li>\n<li>Select GlobalAssemblyInfo.cs</li>\n<li>Expand the Add-Button by clicking on that little down-arrow on the right hand</li>\n<li>Select "Add As Link" in the buttons drop down list</li>\n</ul>\n'}, {'answer_id': 62703, 'author': 'Cameron MacFarland', 'author_id': 3820, 'author_profile': 'https://Stackoverflow.com/users/3820', 'pm_score': 2, 'selected': False, 'text': '<p>To share a file between multiple projects you can add an existing file as a link.</p>\n\n<p>To do this, add an existing file, and click on "Add as Link" in the file selector.<a href="http://laurent.etiemble.free.fr/dotclear/images/AddLinkedFile03.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4Ka4.png" alt="Add As Link"></a><br>\n<sub>(source: <a href="http://laurent.etiemble.free.fr/dotclear/images/AddLinkedFile03_tn.png" rel="nofollow noreferrer">free.fr</a>)</sub>  </p>\n\n<p>As for what to put in the shared file, I would suggest putting things that would be shared across assemblies. Things like copyright, company, perhaps version.</p>\n'}, {'answer_id': 62739, 'author': 'Krishna', 'author_id': 6995, 'author_profile': 'https://Stackoverflow.com/users/6995', 'pm_score': 4, 'selected': False, 'text': '<p>In my case, we\'re building a product for which we have a Visual Studio solution, with various components in their own projects. The common attributes go. In the solution, there are about 35 projects, and a common assembly info (CommonAssemblyInfo.cs), which has the following attributes:</p>\n\n<pre><code>[assembly: AssemblyCompany("Company")]\n[assembly: AssemblyProduct("Product Name")]\n[assembly: AssemblyCopyright("Copyright © 2007 Company")]\n[assembly: AssemblyTrademark("Company")]\n\n//This shows up as Product Version in Windows Explorer\n//We make this the same for all files in a particular product version. And increment it globally for all projects.\n//We then use this as the Product Version in installers as well (for example built using Wix).\n[assembly: AssemblyInformationalVersion("0.9.2.0")]\n</code></pre>\n\n<p>The other attributes such as AssemblyTitle, AssemblyVersion etc, we supply on a per-assembly basis. When building an assembly both AssemblyInfo.cs and CommonAssemblyInfo.cs are built into each assembly. This gives us the best of both worlds where you may want to have some common attributes for all projects and specific values for some others.</p>\n\n<p>Hope that helps.</p>\n'}, {'answer_id': 63000, 'author': 'jlew', 'author_id': 7450, 'author_profile': 'https://Stackoverflow.com/users/7450', 'pm_score': 3, 'selected': False, 'text': '<p><a href="https://github.com/loresoft/msbuildtasks" rel="nofollow noreferrer">MSBuild Community Tasks</a> contains a custom task called AssemblyInfo which you can use to generate your assemblyinfo.cs.  It requires a little hand-editing of your csproj files to use, but is worthwhile. </p>\n'}, {'answer_id': 63132, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 4, 'selected': False, 'text': '<p>The solution presented by @JRoppert is almost the same as what I do. The only difference is that I put the following lines in the local AssemblyInfo.cs file as they can vary with each assembly:</p>\n\n<pre><code>#if DEBUG\n[assembly: AssemblyConfiguration("Debug")]\n#else\n[assembly: AssemblyConfiguration("Release")]\n#endif\n[assembly: AssemblyVersion("This is set by build process")]\n[assembly: AssemblyFileVersion("This is set by build process")]\n[assembly: CLSCompliant(true)]\n</code></pre>\n\n<p>I also (generally) use one common assembly info per solution, with the assumption that one solution is a single product line/releasable product. The common assembly info file also has:</p>\n\n<pre><code>[assembly: AssemblyInformationalVersion("0.9.2.0")]\n</code></pre>\n\n<p>Which will set the "ProductVersion" value displayed by Windows Explorer.</p>\n'}, {'answer_id': 25117433, 'author': 'Jack Ukleja', 'author_id': 61714, 'author_profile': 'https://Stackoverflow.com/users/61714', 'pm_score': 3, 'selected': False, 'text': '<p>In my opinion using a GlobalAssemblyInfo.cs is more trouble than it\'s worth, because you need to modify every project file and remember to modify every new project, whereas you get an AssemblyInfo.cs by default.</p>\n\n<p>For changes to global values (i.e. Company, Product etc) the changes are usually so infrequent and simple to manage I don\'t think <a href="http://en.wikipedia.org/wiki/Don&#39;t_repeat_yourself" rel="noreferrer">DRY</a> should be a consideration. Just run the following MSBuild script (dependent on the <a href="http://mikefourie.github.io/MSBuildExtensionPack/" rel="noreferrer">MSBuild Extension Pack</a>) when you want to manually change the values in all projects as a one-off:</p>\n\n<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;\n&lt;Project ToolsVersion="4.0" DefaultTargets="UpdateAssemblyInfo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;\n\n    &lt;ItemGroup&gt;\n        &lt;AllAssemblyInfoFiles Include="..\\**\\AssemblyInfo.cs" /&gt;\n    &lt;/ItemGroup&gt;\n\n    &lt;Import Project="MSBuild.ExtensionPack.tasks" /&gt;\n\n  &lt;Target Name="UpdateAssemblyInfo"&gt;\n    &lt;Message Text="%(AllAssemblyInfoFiles.FullPath)" /&gt;\n    &lt;MSBuild.ExtensionPack.Framework.AssemblyInfo \n        AssemblyInfoFiles="@(AllAssemblyInfoFiles)"\n        AssemblyCompany="Company"\n        AssemblyProduct="Product"\n        AssemblyCopyright="Copyright"\n        ... etc ...\n        /&gt;\n  &lt;/Target&gt;\n\n&lt;/Project&gt;\n</code></pre>\n'}, {'answer_id': 39352322, 'author': 'John Denniston', 'author_id': 4511145, 'author_profile': 'https://Stackoverflow.com/users/4511145', 'pm_score': 1, 'selected': False, 'text': '<p>One thing I have found useful is to generate the AssemblyVersion elements (etc) by applying token-substitution in the pre-build phase.</p>\n\n<p>I use TortoiseSvn, and it is easy to use its <code>SubWCRev.exe</code> to turn a template <code>AssemblyInfo.wcrev</code> into <code>AssemblyInfo.cs</code>.  The relevant line in the template might look something like this:</p>\n\n<pre><code>[assembly: AssemblyVersion("2.3.$WCREV$.$WCMODS?1:0$$WCUNVER?1:0$")]\n</code></pre>\n\n<p>The third element is then the revision number.  I use the fourth element to check I haven\'t forgotten to commit any new or changed files (the fourth element is 00 if it is all OK).</p>\n\n<p>By the way, add <code>AssemblyInfo.wcrev</code> to your version control and <strong>ignore</strong> <code>AssemblyInfo.cs</code> if you use this.</p>\n'}]
['https://Stackoverflow.com/questions/62353', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2361/']