470,618 Members | 1,723 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

AssemblyKeyFile relative to?

Nak
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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #1
18 9189
Nak
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.

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #2
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.
==================================
Nov 20 '05 #3
Nak
> 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...ongnaming.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
:-)

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #4
Hello,

"Fergus Cooney" <fi******@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

Nov 20 '05 #5
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."

Nov 20 '05 #6
Nak
> 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.

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #7
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-****@online.microsoft.com (Kevin Yu) wrote in message news:<#l*************@cpmsftngxa06.phx.gbl>...
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."

Nov 20 '05 #8
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?

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

Nov 20 '05 #9
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-****@online.microsoft.com (Kevin Yu) wrote in message news:<PY*************@cpmsftngxa06.phx.gbl>... 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?

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

Nov 20 '05 #10
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")>.

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

Nov 20 '05 #11
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-****@online.microsoft.com (Kevin Yu) wrote in message news:<R#**************@cpmsftngxa06.phx.gbl>...
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")>.

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

Nov 20 '05 #12
Nak
> 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.

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #13
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.

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

Nov 20 '05 #14
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-****@online.microsoft.com (Kevin Yu) wrote in message news:<JQ**************@cpmsftngxa06.phx.gbl>...
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.

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

Nov 20 '05 #15
Hi Norm,

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

%HomePath% can be got as
System.Environment.GetEnvironmentVariable("HomeDri ve") +
System.Environment.GetEnvironmentVariable("HomePat h")

And MachineName as System.Environment.MachineName.

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

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

Nov 20 '05 #16
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-****@online.microsoft.com (Kevin Yu) wrote in message news:<Cd**************@cpmsftngxa07.phx.gbl>...
Hi Norm,

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

%HomePath% can be got as
System.Environment.GetEnvironmentVariable("HomeDri ve") +
System.Environment.GetEnvironmentVariable("HomePat h")

And MachineName as System.Environment.MachineName.

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

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

Nov 20 '05 #17
Nak
> 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! :-)

Nick.

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

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #18
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/de...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: <21**************************@posting.google.com >
| References: <Oi*************@TK2MSFTNGP10.phx.gbl>
<#l*************@cpmsftngxa06.phx.gbl>
<21**************************@posting.google.com >
<PY*************@cpmsftngxa06.phx.gbl>
<21**************************@posting.google.com >
<R#**************@cpmsftngxa06.phx.gbl>
<21**************************@posting.google.com >
<JQ**************@cpmsftngxa06.phx.gbl>
<21**************************@posting.google.com >
<Cd**************@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: gr**********@google.com
| NNTP-Posting-Date: 15 Sep 2003 13:19:54 GMT
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA06.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!s n-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
|
| 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-****@online.microsoft.com (Kevin Yu) wrote in message
news:<Cd**************@cpmsftngxa07.phx.gbl>...
| > Hi Norm,
| >
| > You don't need to hardcode them in your program.
| >
| > %HomePath% can be got as
| > System.Environment.GetEnvironmentVariable("HomeDri ve") +
| > System.Environment.GetEnvironmentVariable("HomePat h")
| >
| > And MachineName as System.Environment.MachineName.
| >
| > However, I recommend you use relative path instead. It could be
| > "..\\..\\App.snk"
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
|

Nov 20 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ram | last post: by
1 post views Thread by George Durzi | last post: by
reply views Thread by Ram | last post: by
4 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.