Cannot Sign C# Assembly with a Strong Name
According to the Microsoft documentation (ref), to sign an assembly you need to specify the /keyfile:path
compiler argument. Adding this option from the IDE, it will add the following tags to the .csproj:
<AssemblyOriginatorKeyFile>path</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
CMake fails to add these tags for two reasons:
- It detects the
keyfile
compiler option and try to generate theAssemblyOriginatorKeyFile
, but in cmVS11CSharpFlagTable.h, it says that it doesn't have any user value (constant is0x00
instead of0x20
), so the tag is empty. We can't specify where is the key file. - It doesn't parse or add the
SignAssembly
tag.
Trying to use the format /keyfile:path
won't match and it will go to the AdditionalOptions
tag that it's ignored by the C# compiler.
The workaround is to use the property VS_GLOBAL_tag
for instance:
set_target_properties(target PROPERTIES
VS_GLOBAL_SignAssembly "true"
VS_GLOBAL_AssemblyOriginatorKeyFile "${SIGN_KEY}"
)