Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AssemblyKeyFile relative to?

199 views
Skip to first unread message

Nak

unread,
Sep 6, 2003, 7:25:24 AM9/6/03
to
Hi there,

Does anyone know what path the AssemblyKeyFile attribute is relative to?
For example I currently have mine set to

<Assembly: AssemblyKeyFile("..\NicksKey.snk")>

Sometimes this works, and sometimes I need to change it to

<Assembly: AssemblyKeyFile("..\..\NicksKey.snk")>

Which could only mean that sometimes it is relative to the projects root
and sometimes it is relative to the compiled executable. I'm looking around
on the web for this one too, but does anyone else know what it is relative
too? I only want to have 1 copy of the snk file, hence using a relative
path, and I didn't want to use the full path (Even though I might have to).
Thanks again!!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


Nak

unread,
Sep 6, 2003, 7:33:33 AM9/6/03
to
I also believe that this *may* only be happening with 1 project, the project
is in a solution with 1 other project. I can't replecate when it will
require either path as yet, but I'm sure there must be an explanation for
it.

Fergus Cooney

unread,
Sep 6, 2003, 1:39:39 PM9/6/03
to
Hi Nick,

No answer, just my own question - what's a .snk file ? Nothing sneaky, I hope, lol.

Regards,
Fergus

==================================
Call that code? That's not even pseudo code!!
I'm telling Jack on you.
He'll have something to say about it, that's for sure.
==================================


Nak

unread,
Sep 6, 2003, 1:45:14 PM9/6/03
to
> No answer, just my own question - what's a .snk file ? Nothing sneaky,
I hope, lol.

Hi Fergus,

It's something quite interesting that means that my assembly's are going
to be a damn sight more secure from crackers than they were before! It's a
"strong named key" file,

http://www.ondotnet.com/pub/a/dotnet/2003/04/28/strongnaming.html

I found this URL on the web while looking up RSA encryption again and
was quite suprised that I hadn't found out about it before. It's worth
having a look at and if you plan on distributing software, use it!
especially if you want to sell it! Seems like quite a good site that one
:-)

Herfried K. Wagner [MVP]

unread,
Sep 6, 2003, 8:27:12 PM9/6/03
to
Hello,

"Fergus Cooney" <filt...@tesco.net> schrieb:


> No answer, just my own question - what's a .snk file ? Nothing
> sneaky, I hope, lol.

AFAIK "SNK" = "Strong Name Key". A SNK file can be created with the
"Sn.exe" utility. Have a look at the docs for "Strong Name" for more
information.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Kevin Yu

unread,
Sep 8, 2003, 8:41:17 AM9/8/03
to
Hi Nick,

The path for the AssemblyKeyFile attribute is relative to the project
output directory. It means that it is relative to the path where the
generated .exe or .dll file exists. Generally, the .exe or dll file is put
in the projectfolder\bin\debug folder when debugging. So, if your strong
name key file have to be ..\..\strongnamekey.snk.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nak

unread,
Sep 8, 2003, 10:29:12 AM9/8/03
to
> The path for the AssemblyKeyFile attribute is relative to the project
> output directory. It means that it is relative to the path where the
> generated .exe or .dll file exists. Generally, the .exe or dll file is put
> in the projectfolder\bin\debug folder when debugging. So, if your strong
> name key file have to be ..\..\strongnamekey.snk.

Hi Kevin,

Thanks for the information, this is what I had presumed, but for some
reason I get told sometimes that my key cannot be found, even though it was
used successfuly last compile. The only way I can get around this is by
changing the path from

..\..\strongnamekey.snk

to..

..\strongnamekey.snk

or vise versa

This is strange because that means that sometimes it is relative to the
debug folder, this is and example of my directory layout,

strongnamekey.snk
project folder\
bin\compiled program.exe
obj\debug\compiled program.exe

Hence having to swap around sometimes. I have no problems with changing
the value when necessary but would just like to understand under what
circumstances that VB would make the key relative to the debug exe. Thanks
again for your advice.

Norm Dotti

unread,
Sep 9, 2003, 8:59:52 AM9/9/03
to
Kevin,

Since we went from VS 2002 to VS 2003 I can not get a relative path to
work for this attribute in a web service project (it worked in 2002).
If I fully specify it it's ok, but if I try a relative it simply says
it cannot find the file specified. How do I get relative path to work
for a web service project?


v-k...@online.microsoft.com (Kevin Yu) wrote in message news:<#lleIagd...@cpmsftngxa06.phx.gbl>...

Kevin Yu

unread,
Sep 10, 2003, 2:55:59 AM9/10/03
to
Hi Norm,

The location of the project output directory is dependent on whether you
are working with a local or web project. For local projects, the project
output directory is defined as <Project Directory>\obj\<Configuration>. For
example, if your KeyFile is located in the project directory, you would
specify the AssemblyKeyFile attribute as [assembly:
AssemblyKeyFile("..\\..\\mykey.snk")] For web projects, the project output
directory is defined as %HOMEPATH%\VSWebCache\<Machine Name>\<Project
Directory>\obj\<Configuration>.

Please check the folder to see if the strong name key file is there. If you
have already put the strong name key file there, would you please tell me
the error message when compiling?

Norm Dotti

unread,
Sep 10, 2003, 10:12:54 AM9/10/03
to
Kevin,

Here's my directory structure:

e:\Solution\App\
|
|__Control Project
|
|__WinForm Project
|
|__WebService Project
|
|__Other Projects

My snk file resides in e:\Solution\App. All projects except the Web
Service one have the following in their AssemblyInfo file:

<Assembly: AssemblyKeyFile("..\..\..\App.snk")>

In VS2002 I simply had the following for the Web Service project:

<Assembly: AssemblyKeyFile("App.snk")>

and it worked fine. Since VS2003 I can't seem to do anything relative
AssemblyKeyFile attribute for the Web Service project. Absolutes work,
but not relatives. I have IIS set so that the default home directory
is e:\Solution. The Web Service project's VRoot local directory is set
to e:\Solution\App\WebService.

I did put the snk file in %HOMEPATH%\VSWebCache\<Machine
Name>\<Project
> Directory>\obj\DEBUG as you suggested. I still get the "can't find it" message. Is this a change from VS2002? Because it used to work.

Any ideas would be appreciated.


v-k...@online.microsoft.com (Kevin Yu) wrote in message news:<PYfxZi2...@cpmsftngxa06.phx.gbl>...

Kevin Yu

unread,
Sep 10, 2003, 11:38:10 PM9/10/03
to
Hi Norm,

%HOMEPATH%\VSWebCache\<Machine Name>\<Project Directory>\obj\DEBUG is the
directory your AssemblyKeyFile attribute relative to. Generally, We put the
strong name key in the %HOMEPATH%\VSWebCache\<Machine Name>\<Project
Directory>\

Please take a look at the AssemblyKeyFile attribute. It has to be
<Assembly: AssemblyKeyFile("..\\..\\App.snk")>, if your key file is put in
%HOMEPATH%\VSWebCache\<Machine Name>\<Project Directory>\ Note that you
have to use double “\” in the string.

If you put the key file in %HOMEPATH%\VSWebCache\<Machine Name>\<Project
Directory>\obj\DEBUG, the attribute has to be set as <Assembly:
AssemblyKeyFile("App.snk")>.

Norm Dotti

unread,
Sep 11, 2003, 4:40:16 PM9/11/03
to
It does work now. This is a bit of an inconvenienve though. I've got
my application directories and files on my E: drive yet it's got to
looks on my C: drive as the relative start position for web service
apps? I wish they hadn't changed this. I don't want to have to keep
two copies of the snk file. I can't seem to point to the same one
though (in a relative manner). I don't want to hard code it because
not all machines have the same drive mappings. Any other ideas?

v-k...@online.microsoft.com (Kevin Yu) wrote in message news:<R#66jYBeD...@cpmsftngxa06.phx.gbl>...

Nak

unread,
Sep 11, 2003, 5:39:30 PM9/11/03
to
> It does work now. This is a bit of an inconvenienve though. I've got
> my application directories and files on my E: drive yet it's got to
> looks on my C: drive as the relative start position for web service
> apps? I wish they hadn't changed this. I don't want to have to keep
> two copies of the snk file. I can't seem to point to the same one
> though (in a relative manner). I don't want to hard code it because
> not all machines have the same drive mappings. Any other ideas?

Hi there,

I understand exactly what you mean about have 2 copies of the snk file.
I think it is a security risk to have more than one. As well as being much
easier to backup your data if it is all in 1 path.

Kevin Yu

unread,
Sep 11, 2003, 11:16:02 PM9/11/03
to
Hi Norm,

Actually, you only need to maintain one copy of the key file, just put it
under the folder %HOMEPATH%\VSWebCache\<Machine Name>\<Project Directory>\.
Another one in the project folder is not required.

Norm Dotti

unread,
Sep 12, 2003, 2:05:56 PM9/12/03
to
Are %HOMEPATH% and <Machine Name> treated as variables or do I need to
replace them with hardcoded values? It's not working as is.


v-k...@online.microsoft.com (Kevin Yu) wrote in message news:<JQqlAxNe...@cpmsftngxa06.phx.gbl>...

Kevin Yu

unread,
Sep 14, 2003, 11:35:17 PM9/14/03
to
Hi Norm,

You don't need to hardcode them in your program.

%HomePath% can be got as
System.Environment.GetEnvironmentVariable("HomeDrive") +
System.Environment.GetEnvironmentVariable("HomePath")

And MachineName as System.Environment.MachineName.

However, I recommend you use relative path instead. It could be
"..\\..\\App.snk"

Norm Dotti

unread,
Sep 15, 2003, 9:19:53 AM9/15/03
to
I agree, relative path is the way to go. I've been trying to use
relative path all along. As you may recall ..\\..\\App.snk doesn't
work for the Web Service project. I have may apps on E: but the web
service's "home" relative start directory is on C:.

Please tell me how to provide a relative, non-machine/user dependent
path for all my project types that point to the same snk file. I don't
see how this is possible.


v-k...@online.microsoft.com (Kevin Yu) wrote in message news:<CdbWnpze...@cpmsftngxa07.phx.gbl>...

Nak

unread,
Sep 15, 2003, 4:30:40 PM9/15/03
to
> I agree, relative path is the way to go. I've been trying to use
> relative path all along. As you may recall ..\\..\\App.snk doesn't
> work for the Web Service project. I have may apps on E: but the web
> service's "home" relative start directory is on C:.

Hi there,

A path is only "relative" to another path if it is on the same drive.
So if the snk file is on another drive you would not be using a relative
path, but the exact path. I can't see how you could do it any other way if
the file is contained on another drive, more to the point, why would you
want to? Or is it not even picking it up on another drive?, mine looses the
key file every now and then and I have to restart VB to get it to find it
again! :-)

Kevin Yu

unread,
Sep 16, 2003, 1:23:31 AM9/16/03
to
Hi Norm,

Visual Studio .NET will not search for the strong name key file under the
project folder but under the VSWebCache folder when you're working on a web
service project. So you have to copy a key file to the VSWebCache folder to
get a relative path.

If you want to keep your private key file safe and only want to maintain
one copy of the strong name key file for all the projects, you can use
Delay Signing. Delayed signing at build time allow you to reserve space in
the portable executable (PE) file for the strong name signature, but defer
the actual signing until some later stage (typically just before shipping
the assembly).

Please refer to the following link for more information:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpcondelayedsigningassembly.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: no...@knorrassociates.com (Norm Dotti)
| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Re: AssemblyKeyFile relative to?
| Date: 15 Sep 2003 06:19:53 -0700
| Organization: http://groups.google.com/
| Lines: 28
| Message-ID: <219f4ebc.03091...@posting.google.com>
| References: <OiYRRmG...@TK2MSFTNGP10.phx.gbl>
<#lleIagd...@cpmsftngxa06.phx.gbl>
<219f4ebc.03090...@posting.google.com>
<PYfxZi2...@cpmsftngxa06.phx.gbl>
<219f4ebc.03091...@posting.google.com>
<R#66jYBeD...@cpmsftngxa06.phx.gbl>
<219f4ebc.03091...@posting.google.com>
<JQqlAxNe...@cpmsftngxa06.phx.gbl>
<219f4ebc.03091...@posting.google.com>
<CdbWnpze...@cpmsftngxa07.phx.gbl>
| NNTP-Posting-Host: 67.85.172.14
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1063631994 6408 127.0.0.1 (15 Sep 2003
13:19:54 GMT)
| X-Complaints-To: groups...@google.com
| NNTP-Posting-Date: 15 Sep 2003 13:19:54 GMT
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.com!prodigy.c
om!pd2nf1so.cg.shawcable.net!residential.shaw.ca!sn-xit-03!sn-xit-01!sn-xit-
08!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:137012
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb

0 new messages