Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Task to read version of dll

Tags:

msbuild

I am looking for a MSBuild task that will tell me the version of a specific dll. Is there a task available for this?

In my case the dll is a .Net assembly, so I'm actually looking for Assembly.FullName.

like image 546
Mike Schall Avatar asked Jan 14 '09 14:01

Mike Schall


2 Answers

GetAssemblyIdentity is your man. This task outputs contain item metadata entries named Version, PublicKeyToken, and Culture.

<ItemGroup>
    <MyAssemblies Include="File1.dll;File2.dll" />
</ItemGroup>

<Target Name="RetrieveIdentities>
    <GetAssemblyIdentity
        AssemblyFiles="@(MyAssemblies)">
        <Output
            TaskParameter="Assemblies"
            ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>
</Target>
like image 78
Julien Hoarau Avatar answered Oct 22 '22 17:10

Julien Hoarau


Thanks madgnome! I thought I would share the working code.

<Target Name="UpdateWebConfigVersion">
    <GetAssemblyIdentity AssemblyFiles="lib\foo.dll">
        <Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
    </GetAssemblyIdentity>
    <XmlUpdate XmlFileName="src\Web\ServiceModel.Extensions.config"
            XPath="//extensions/behaviorExtensions/add[@name='silverlightFaults']/@type"
            Value="foo.ServiceModel.Extensions.Behaviors.SilverlightFaultBehavior, foo, Version=%(fooAssemblyInfo.Version), Culture=neutral, PublicKeyToken=XXXXXXXX"/>
</Target>
like image 41
Mike Schall Avatar answered Oct 22 '22 16:10

Mike Schall