Recent Posts

Categories

Archives

Calendar

March 2010
M T W T F S S
« Jan    
1234567
891011121314
15161718192021
22232425262728
293031  

Search


Meta

Run this program as program as an administrator

Vista will try and run most programs without admin rights even if you are signed on as an admin. Some programs such as Visual Studio need admin rights so it is worth setting them to always run as administrator.

Confusingly, looking at a shortcut’s properties, the compatibility tab has an option to “Run this program as an administrator”. This option is greyed out:

Shortcut Compatibility Tab

To set the shortcut to run as administrator go to the shortcut tab > click on Advanced… > check Run as administrator:

Shortcut Advanced Properties

 

How to Use InternalsVisibleTo

VS2005 defaults new classes to internal rather than public (although it appears that Orcas defaults to public). This is good as it reduces the public interface of your assembly and it encourages you to actually think about whether a class needs to be public.

You can allow other assemblies access to your internal types and members though, by using the InternalsVisibleTo attribute. This is especially useful for allowing your test assembly to access your internal classes.

This attribute can only be applied to strongly named assemblies.

[assembly:InternalsVisibleTo("TestAssembly, PublicKey=TestAssembly’s public key")]

The attribute requires the assembly name and the public key. To retrieve the public key use sn.exe. Open a visual studio command prompt and enter:

sn.exe -Tp AssemblyPath

Alternatively if you use an alternate file explorer you could set up a macro.

How to Give an Assembly a Strong Name

To Strongly name an assembly you need to associate it with a public and private key. This can be either done by the developer when they compile the assembly (signing) or by at a later stage for instance by the QA department (delayed signing).

Public and private keys can be associated with code signing certificates, generated using sn.exe, or they can be generated from within Visual Studio.

Open the project properties for the assembly you want to sign and check ‘sign the assembly’ on the signing tab. To create a key file, select New from the drop down and follow the directions or Browse for an existing key file. If you create a key file it is worth moving it from the bin directory as you should be using it across multiple projects.

Once compiled you will have a signed assembly with a strong name.