You Have been Signing .NET Assemblies wrong!
Don’t hard code you Signing Key file Path!
For a long time, if I want to sign an assembly I’ll put this line into the AssemblyInfo.cs
file
[assembly: AssemblyKeyFile(@"<PATH_TO_FILE>\file.snk")]
This is fine until we want to automate the build on a build Server which could have a deferent path. The build will fail!
The right Way
- Remove that line from AssemblyInfo.
- Change the project file to add these propertyGroup:
- Add
<keyFilePath><PATH_TO_FILE>\file.snk</keyFilePath>
. - Add this code to the project file
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>$(keyFilePath)</AssemblyOriginatorKeyFile>
</PropertyGroup>
- Now you can override the path on build by providing
/p:keyFilePath="%KEY_FILE_PATH%"
to MsBuild.
Written on April 19, 2017