Thursday 23 October 2008

sgen.exe /compiler:/keyfile Doesn't Allow Spaces

While implementing a bit of .NET code that will ultimately live in SQL Server 2005, we came across a few minor problems with the auto-generated XmlSerializers.dll and, in particular, signing it with a key file. The assembly calls out to a web service, hence the need for the XmlSerializers.dll.

Normally you can tell Visual Studio to build this assembly for you at compile time: Project properties -> Build Tab, Generate serialization assembly = On | off (note this is set per configuration, eg. Debug, Release). SQL Server had a few problems around versioning with the generated assembly, however, so we decided to add a post-build event and use sgen.exe explicitly to manage this at build time. 

Soon after we also decided the main assembly and XmlSerializers assembly would need to be signed, as it's also being called from another bit of code in MOSS; we naturally figured adding the /compiler:/keyfile flags would take care of this.

The path to our .snk file has spaces, however, and the keyfile flag doesn't seem to like spaces. Initially I thought we would simply xcopy the .snk file to the c: drive and then reference it directly from there but that's dirty. 

In the end, there is a way to escape the quotes in the string: 

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /compiler:"\"/keyfile:$(ProjectDir)MyKeyFile.snk"\" /force "$(TargetPath)"

Custom-Built Microsoft Office SharePoint Server 2007 Branded Sites and Webpart Development -

No comments:

Post a Comment

Spam comments will be deleted

Note: only a member of this blog may post a comment.