views:

597

answers:

1

All

I am fairly comfortable with writing assembly version information for a given project that will output as a DLL.

However what I am looking to do now is to go through each DLL in a \Bin folder, retrieve the Assembly information and write it to a versions.txt file.

Has anyone managed to acheive a similar goal?

+1  A: 

You can to that using WriteVersionToFile MSBuild target defined below :

<PropertyGroup>
  <VersionsFile>versions.txt</VersionsFile>
</PropertyGroup> 

<ItemGroup>
  <!-- Assemblies for which you want versions-->
  <AssemblyFiles Include="Bin\**\*.dll"/>
</ItemGroup>

<Target Name="ExtractVersions">
  <GetAssemblyIdentity AssemblyFiles="@(AssemblyFiles)">
    <Output TaskParameter="Assemblies" ItemName="MyAssemblyIdentities"/>
  </GetAssemblyIdentity>
  <Message Text="%(MyAssemblyIdentities.Name) - Version %(Version)"/>
</Target>

<Target Name="WriteVersionToFile" DependsOnTargets="ExtractVersions">
  <Delete Files="$(VersionsFile)" />
  <WriteLinesToFile File="$(VersionsFile)"
                    Lines="%(MyAssemblyIdentities.Name) - %(Version)"
                    Overwrite="false"
                    Encoding="Unicode"/>
</Target>


Output file versions.txt will look like that :

ICSharpCode.SharpZipLib - 0.85.4.369
nunit.framework - 2.4.7.0
Test.Rules - 0.2.0.0
madgnome
Get error for me: error MSB4064: "Encoding" parameter not compatible with "WriteLinesToFile" task
alhambraeidos