57

I want to run regasm.exe from cmd. which is available in c:\windows\Microsoft.net\framework\2.057

I do like this c:\ regasm.exe

It gives regasm is not recognized as internal or external command.

So I understood that I need to set the path for regasm.exe in environment variable.

For which variable do I need to set the path to run regasm as described above?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Cute
  • 13,643
  • 36
  • 96
  • 112

10 Answers10

47

In command prompt:

SET PATH = "%PATH%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727"
Martin Verjans
  • 4,675
  • 1
  • 21
  • 48
  • 11
    Better still: SET PATH "%PATH%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727" – Ries Sep 04 '09 at 08:33
  • 3
    @CharlieSomerville Could you just fix the original? It's too small for someone else to edit. – Carl Onager Apr 02 '13 at 10:43
  • I could not get this to work without adding an equals. I tried to edit it but SO said the edit was too short. `SET PATH = "%PATH%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727` – KevM Jun 05 '15 at 17:24
  • But, what if there is no "Framework" folder in the Microsoft.NET folder ? I ended up on this SO question because there is no visual studio in my production environment (which is gonna be the case for most production environements), and I don't have this framwork folder, even though IIS can run my .NET websites. – Virus721 Aug 07 '23 at 07:47
41

Like Cheeso said:

You don't need the directory on your path. You could put it on your path, but you don't NEED to do that. If you are calling regasm rarely, or calling it from a batch file, you may find it is simpler to just invoke regasm via the fully-qualified pathname on the exe, eg:

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe MyAssembly.dll

Ries
  • 2,844
  • 4
  • 32
  • 45
23

You don't need the directory on your path. You could put it on your path, but you don't NEED to do that.
If you are calling regasm rarely, or calling it from a batch file, you may find it is simpler to just invoke regasm via the fully-qualified pathname on the exe, eg:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe   MyAssembly.dll
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 1
    The problem with that is you OS may be in winnt or some other folder instead of Windows, so it's better to use %systemroot% as the other responses show – Alex Nov 05 '10 at 14:41
21

If you created the DLL using .net 4.5 , then copy and paste this command on command prompt.

 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm.exe MyAssembly.dll
Matt
  • 45,022
  • 8
  • 78
  • 119
Edwin O.
  • 4,998
  • 41
  • 44
8

I use this as post-build event in Visual Studio:

call "%VS90COMNTOOLS%vsvars32.bat"
regasm  $(TargetPath) /tlb

Depending on your Visual Studio version, use these environment variables instead:

  1. Visual Studio 2008: VS90COMNTOOLS
  2. Visual Studio 2010: VS100COMNTOOLS
  3. Visual Studio 2012: VS110COMNTOOLS
  4. Visual Studio 2013: VS120COMNTOOLS
  5. Visual Studio 2015: VS140COMNTOOLS
  6. Visual Studio 2017: VS150COMNTOOLS
Christian
  • 9,914
  • 6
  • 45
  • 52
Unrumpf
  • 81
  • 1
  • 1
2

I really dislike the hard coding of paths to get to regasm, when you install a new .Net or run on a machine with a different version, you need to ensure you find a version of regasm. Here's a solution to find the regasm.exe from the most current .Net installed regasm.

Within a bat file:

for /f %%a in ('dir %windir%\Microsoft.Net\Framework\regasm.exe /s /b') do set currentRegasm="%%a"
%currentRegasm% "full\path\to\your.dll" /options

Outside of a bat file (i.e. command prompt), just use %a instead of %%a

Scott C
  • 1,660
  • 1
  • 11
  • 18
2

I use the following in a batch file:

path = %path%;C:\Windows\Microsoft.NET\Framework\v2.0.50727
regasm httpHelper\bin\Debug\httpHelper.dll /tlb:.\httpHelper.tlb /codebase
pause
Community
  • 1
  • 1
Patrick
  • 8,175
  • 7
  • 56
  • 72
1

Execute only 1 of the below
Once a command works, skip the rest/ below to it:

Normal:

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe myTest.dll
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe myTest.dll /tlb:myTest.tlb
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe myTest.dll /tlb:myTest.tlb /codebase

Only if you face issues, use old version 'v2.0.50727':

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe myTest.dll
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe myTest.dll /tlb:myTest.tlb
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe myTest.dll /tlb:myTest.tlb 

Only if you built myTest.dll for 64bit Only, use 'Framework64' path:

%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe myTest.dll
%SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\RegAsm.exe myTest.dll

Note: 64-bit built dlls will not work on 32-bit platform.

All options:

See https://learn.microsoft.com/en-us/dotnet/framework/tools/regasm-exe-assembly-registration-tool

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
0

For the 64-bit RegAsm.exe you will need to find it someplace like this:

c:\Windows\Microsoft.NET\Framework64\version_number_stuff\regasm.exe
Jiminion
  • 5,080
  • 1
  • 31
  • 54
0

By dragging and dropping the dll onto 'regasm' you can register it. You can open two 'Window Explorer' windows. One will contain the dll you wish to register. The 2nd window will be the location of the 'regasm' application. Scroll down in both windows so that you have a view of both the dll and 'regasm'. It helps to reduce the size of the two windows so they are side-by-side. Be sure to drag the dll over the 'regasm' that is labeled 'application'. There are several 'regasm' files but you only want the application.