简体   繁体   English

如何从Visual Studio命令提示符以外的命令行运行regasm.exe?

[英]How to run regasm.exe from command line other than Visual Studio command prompt?

I want to run regasm.exe from cmd. 我想从cmd运行regasm.exe。 which is available in c:\\windows\\Microsoft.net\\framework\\2.057 可在c:\\ windows \\ Microsoft.net \\ framework \\ 2.057中找到

I do like this c:\\ regasm.exe 我喜欢这个c:\\ regasm.exe

It gives regasm is not recognized as internal or external command . 它给予regasm不被认为是内部或外部命令

So I understood that I need to set the path for regasm.exe in environment variable. 所以我明白我需要在环境变量中设置regasm.exe的路径。

For which variable do I need to set the path to run regasm as described above? 如上所述,我需要为哪个变量设置运行regasm的路径?

在命令提示符下:

SET PATH = "%PATH%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727"

Like Cheeso said: 像Cheeso说:

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: 如果您很少调用regasm,或者从批处理文件中调用它,您可能会发现通过exe上的完全限定路径名调用regasm更简单,例如:

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

如果使用.net 4.5创建DLL,则在命令提示符下复制并粘贴此命令。

 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm.exe MyAssembly.dll

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: 如果您很少调用regasm,或者从批处理文件中调用它,您可能会发现通过exe上的完全限定路径名调用regasm更简单,例如:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe   MyAssembly.dll

I use this as post-build event in Visual Studio: 我在Visual Studio中将其用作后期构建事件:

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

Depending on your Visual Studio version, use these environment variables instead: 根据您的Visual Studio版本,请改用以下环境变量:

  1. Visual Studio 2008: VS90COMNTOOLS Visual Studio 2008: VS90COMNTOOLS
  2. Visual Studio 2010: VS100COMNTOOLS Visual Studio 2010: VS100COMNTOOLS
  3. Visual Studio 2012: VS110COMNTOOLS Visual Studio 2012: VS110COMNTOOLS
  4. Visual Studio 2013: VS120COMNTOOLS Visual Studio 2013: VS120COMNTOOLS
  5. Visual Studio 2015: VS140COMNTOOLS Visual Studio 2015: VS140COMNTOOLS
  6. Visual Studio 2017: VS150COMNTOOLS Visual Studio 2017: VS150COMNTOOLS

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

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. 我真的不喜欢硬编码路径来解决问题,当你安装新的.Net或在不同版本的机器上运行时,你需要确保找到一个版本的regasm。 Here's a solution to find the regasm.exe from the most current .Net installed regasm. 这是从最新的.Net安装的regasm中找到regasm.exe的解决方案。

Within a bat file: 在bat文件中:

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 (ie command prompt), just use %a instead of %%a 在bat文件之外(即命令提示符),只需使用%a而不是%%a

对于64位RegAsm.exe,您需要在以下位置找到它:

c:\Windows\Microsoft.NET\Framework64\version_number_stuff\regasm.exe

By dragging and dropping the dll onto 'regasm' you can register it. 通过将dll拖放到'regasm'上,您可以注册它。 You can open two 'Window Explorer' windows. 您可以打开两个“Window Explorer”窗口。 One will contain the dll you wish to register. 一个将包含您要注册的DLL。 The 2nd window will be the location of the 'regasm' application. 第二个窗口将是'regasm'应用程序的位置。 Scroll down in both windows so that you have a view of both the dll and 'regasm'. 在两个窗口中向下滚动,以便您可以看到dll和'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'. 务必将dll拖到标有“application”的'regasm'上。 There are several 'regasm' files but you only want the application. 有几个'regasm'文件但你只想要应用程序。

Execute only 1 of the below 仅执行以下1项
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': 仅当您遇到问题时,请使用旧版本“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: 仅当您为64位仅构建myTest.dll时,才使用“Framework64”路径:

%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. 注意:64位内置dll在32位平台上不起作用。

All options: 所有选项:

See https://docs.microsoft.com/en-us/dotnet/framework/tools/regasm-exe-assembly-registration-tool 请参阅https://docs.microsoft.com/en-us/dotnet/framework/tools/regasm-exe-assembly-registration-tool

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM