AssemblyInfoTask will fail with duplicate entries in AssemblyInfo.cs

AssemblyVersionIncrementer will fail when entries in the AssemblyInfo.cs are not unique. For example:

#if debug    
 AssemblyInfoDescription("Debug mode")
#else
  AssemblyInfoDescription("Release mode") 
#endif 

The version incrementer will read the AssemblyInfo.cs and tries to store the entries in an internal Hashtable. This fails because of the multiple “AssembyInfoDescription” (line 2 and 4) entries (the preprocessor directives are ignored).

Exception text in build log:

Task “AssemblyInfo”
C:Program FilesMSBuildRdwDefaultBuildReleaseAssemblyInfoTaskMicrosoft.VersionNumber.Targets.Test(92,5):
error MSB4018: The “AssemblyInfo” task failed unexpectedly.
error MSB4018: System.ArgumentException: An item with the same key has already been added.
error MSB4018: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
error MSB4018: at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
error MSB4018: at Microsoft.Build.Extras.AssemblyInfoWrapper..ctor(String filename)
error MSB4018: at Microsoft.Build.Extras.AssemblyInfo.Execute()
error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *