Problem:
Generating a strong name key file (.snk) and signing an assembly with such file is common. What if you have to do it for multiple assemblies? For obvious reasons, it is not recommended to generate a separate .snk file for each of your assemblies. There comes the age-old principle of "re-use".
One simple solution this is to use the <Browse...> item in the 'Signing' tab on project properties window and point to the common key file. What's wrong with this approach?
Well...nothing is indeed wrong with it. However, you will observe that this approach creates a copy of the key file in each of your individual project folders. In usual cases, this is not desired. So, the problem now cuts down to the point of determining how to use the same key(as in previous approach), still having it at a single location. Let me put the problem statement in the easiest form - How to share a key file between multiple assemblies?
(Unless you are a beginner or haven't come across such requirement as yet, this should be a known pick.)
Solution:
Generating a strong name key file (.snk) and signing an assembly with such file is common. What if you have to do it for multiple assemblies? For obvious reasons, it is not recommended to generate a separate .snk file for each of your assemblies. There comes the age-old principle of "re-use".
One simple solution this is to use the <Browse...> item in the 'Signing' tab on project properties window and point to the common key file. What's wrong with this approach?
Well...nothing is indeed wrong with it. However, you will observe that this approach creates a copy of the key file in each of your individual project folders. In usual cases, this is not desired. So, the problem now cuts down to the point of determining how to use the same key(as in previous approach), still having it at a single location. Let me put the problem statement in the easiest form - How to share a key file between multiple assemblies?
(Unless you are a beginner or haven't come across such requirement as yet, this should be a known pick.)
Solution:
- Generate a strong name file using the sn utility.
sn –k SomeKey.snk(Refer the msdn documentation for more details on this step) - Place the SomeKey.snk in a location accessible to all your assemblies.
- Add the key file to each of your project folders as an existing item using the context menu
- While adding it, make sure you chose to add it as a link, which will not replicate the file. (Observe the arrow besides the Add button on the Add Existing Item dialog.)
- Go to project properties and on the Singing tab, select the key file from the dropdown.
While doing these, make sure your key file's properties window has Build Action set to None and Output Directory is set to Do Not Copy.
No comments:
Post a Comment
Please help to make the post more helpful with your comments.