Compartir a través de


Get Public Key Token from Snk File using Msbuild

I have written a small msbuild script which can be used to get the public key and the public key token from the .snk file.

This attachment needs to be executed from the visual studio command prompt . Update the WorkingDir and SnkFilePath as needed, after downloading the attachment.

Run it as msbuild <file name>. the output token is in Onlytoken.txt.

The output public key is in OnlyPublic.snk.

Here is the snippet of the same script.

<

Project DefaultTargets="GetPublicKey" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">

<

PropertyGroup>

<

WorkingDir>D:\Work\</WorkingDir>

<

HighLevelErrFile>ErrLog.log</HighLevelErrFile>

<

SnkFilePath>StrongNameKey.Snk</SnkFilePath>

</

PropertyGroup>

<!--

TFS Get Latest Configs-->

<

Target Name="GetPublicKey">

<

WriteLinesToFile File="$(HighLevelErrFile)" Lines=" ============= Operation Started =============" Overwrite="True"/>

<

Exec Command ="sn -p $(SnkFilePath) OnlyPublic.snk" WorkingDirectory ="$(WorkingDir)" />

<

Message Text ="Retrieved Public key from snk file and written to OnlyToken.snk"></Message>

<

Exec Command ="sn -t OnlyPublic.snk > OnlyToken.txt" WorkingDirectory ="$(WorkingDir)" />

<

Message Text ="Done Retrieved Public key token from snk file and written to OnlyToken.txt"></Message>

<

WriteLinesToFile File="$(HighLevelErrFile)" Lines="Done Retrieved Public key token from snk file" Overwrite="false"/>

</

Target>

</

Project>

 

 

GetPublicSnk.msbuild

Comments

  • Anonymous
    October 17, 2012
    Are you using this for "Delayed Signing" or some other purpose?  (I'm just curious to see if there is a different application out there besides "Delayed Signing".)