Wednesday, July 21, 2004

Adding icon to usercontrols [to display in toolbox]

I did find a way doing it manually, but I don't know if it's the correctway to do it ... but it works !1) Create your usercontrol / Component (e.g MyUserControl class) andmarkup the class with[ToolboxBitmap(typeof(Bitmap))] attribute2) Compile this class into a module (Yeha a module, could not get theassembly to work!!)csc /t:module MyUserControl.csThis will create a file called MyUserControl.netmodule3) Create a bitmap 16x16x16, with the fully qualified name of the classthat has the attribute. i.e. namespace.classname.bmpIn my case since the class does not live in a namespace I useMyUserControl.bmp4) Use the al.exe (Assembly Linker) tool to embed the resource.
Al MyUserControl.netmodule
/t:library /embed:MyUserControl.bmp/out:MyUserControl.dll
This step will create an assembly linking the MyUserControl.netmoduleand the embed resource file!5) Add this control to your toolbox !

Wednesday, July 07, 2004

Referring Global assembly from Add Reference dialog box

The typical way of adding references to .NET Components is to use the .NET Tab on the Add Reference…. Dialogue in your project.

VS.NET builds the complete list of available .NET Components by looking in certain directories. By default it looks in the install directory of the .NET Framework (%SystemRoot%\Microsoft.NET\Framework\vSomethingNumber). It will also look in any directory listed with in a certain registry key (see below).

When you are using a nonstandard GAC component, you might want Visual Studio .NET to list it in the Add Reference... dialog under the .NET tab, without having to browse for it.

Simply installing your assembly to the Global Assembly Cache (GAC) would not help in this scenario. The Add Reference dialog box is path based and does not enumerate the components from GAC.

Here is how to install, reference, and use a nonstandard GAC Component:
Create a directory where your nonstandard GAC components will be stored.
ex. “C:\WINDOWS\Microsoft.NET\Framework\[FolderName]
Add a registry key like the one below pointing to where the assembly resides.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

\AssemblyFolders\[FolderName]
@="C:\\WINDOWS\\Microsoft.NET\\Framework\\[FolderName]"
Copy your Strongly Named component to this directory.
Install the component in the GAC (ex. gacutil /i MyComponent.dll)
The GAC’d component will now be available to add as a project reference in the Add Reference… .NET Tab.
NOTE: Since you are referencing a GAC’d component, the Copy Local property will be set to ‘False’. Leave it AS IS. The component will be available in the server GAC when you deploy to the shared environment and should NOT be copied as part of the project.