Right now I am setting the Linker/Advanced/KeyFile option.
I am getting the \"mt.exe : general warning 810100b3: is a strong-name signed assembly and embedding
There's a fair amount of lameness here, this just never worked before. It got "fixed" in VS2010, mt.exe now generates a warning instead of letting this silently go wrong. Not a real fix, and there's not an obvious one, the linker can't just embed the signature and still allow mt.exe to run afterwards.
The solution is to re-sign the assembly with a post-build event. Make it look like this:
Command = sn -Ra "$(TargetPath)" $(ProjectName).snk
If you don't already have the key file, you'll need to create the .snk file yourself, run sn.exe from the Visual Studio Command prompt. for example:
cd \whereTheProjectIsLocated
sn.exe -k MyProject.snk
Or extract it from a container or use your designated key file. Delay signing is just a matter of running sn.exe with the proper command line options.
If you can't/won't edit Microsoft.Cpp.Win32.targets, adding the following to the project file also works:
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- snip -->
<ItemDefinitionGroup>
<Link>
<KeyFile>$(LinkKeyFile)</KeyFile>
</Link>
</ItemDefinitionGroup>
</Project>
Phil Atkin's reply and link is the way to fix this bug. Microsoft finally got around to addressing it for Visual Studio 2010 but they never released a service pack fix. Go to this link for the MS explanation and multiple ways to fix it.
http://blogs.msdn.com/b/vcblog/archive/2011/03/11/10140139.aspx
It worked for me. Thanks Phil. (I'd up vote you, but I'm still a newbie.)
Edit for Mzedeler:
Here is the most relevant info from the link that most people will be able to use. It's skips the history and multi-project implications. (Go to the link to see that stuff.)
First: Fix the typo in the build process:
Redefine the “Key File” and “Delay Sign” properties used for signing your project:
These steps worked for my project. For more details, go to the link above that Phil provided.
End Edit
Paul Mead's proposal is on the right track, but this seems definitive: http://blogs.msdn.com/b/vcblog/archive/2011/03/11/10140139.aspx. Note that it's easy to change the text but omit to change the "%" to a "$".
I ran into this problem with VS2010 SP1 for the WIN32 platform. Looking at the build .log file I found that the /KEYFILE parameter was given to the initial link for the .DLL, but after the manifest was created and the second link was done to include the manifest the /KEYFILE parameter was missing. After looking around a bit I found that the problem is in the file Microsoft.Cpp.Win32.targets in C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32. There is a typo for the KeyFile attribute for the second link. I fixed it by changing line 441:
KeyFile ="%(Link.KeyFile)"
to
KeyFile ="$(LinkKeyFile)"
With that change the second linker pass included the /KeyFile qualifier and the .DLL was properly built with the publickey embedded.
In my experience, the simplest way is to:
1) Open the Visual Studio Command Prompt 2010 . Go to your project directory (it's the directory that contains your source files). Then type sn -k yourKeyName.snk
.
2) Open your project in visual studio 2010 and open up the AssemblyInfo.cpp file and add this line [assembly:AssemblyKeyFileAttribute("yourKeyName.snk")];
.
3) Open up Project->Properties->Linker->Advanced. And in the "Key File" slot and put yourKeyName.snk
. Also in the "Delay Sign" slot select Yes (\DELAYSIGN)
.
4) Build your project as normal.