C++ 如何从 Visual Studio 命令提示符以外的命令行运行 regasm.exe?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/973939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run regasm.exe from command line other than Visual Studio command prompt?
提问by Cute
I want to run regasm.exe from cmd. which is available in c:\windows\Microsoft.net\framework\2.057
我想从 cmd 运行 regasm.exe。在 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 的路径?
采纳答案by anonymous coward
In command prompt:
在命令提示符中:
SET PATH = "%PATH%;%SystemRoot%\Microsoft.NET\Framework\v2.0.50727"
回答by Ries
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
回答by Cheeso
You don't needthe 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
回答by Edwin Ikechukwu Okonkwo
If you created the DLL using .net 4.5 , then copy and paste this command on command prompt.
如果您使用 .net 4.5 创建了 DLL,则在命令提示符下复制并粘贴此命令。
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm.exe MyAssembly.dll
回答by Unrumpf
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 版本,请改用以下环境变量:
- Visual Studio 2008:
VS90COMNTOOLS
- Visual Studio 2010:
VS100COMNTOOLS
- Visual Studio 2012:
VS110COMNTOOLS
- Visual Studio 2013:
VS120COMNTOOLS
- Visual Studio 2015:
VS140COMNTOOLS
- Visual Studio 2017:
VS150COMNTOOLS
- 视觉工作室 2008:
VS90COMNTOOLS
- 视觉工作室 2010:
VS100COMNTOOLS
- 视觉工作室 2012:
VS110COMNTOOLS
- 视觉工作室 2013:
VS120COMNTOOLS
- 视觉工作室 2015:
VS140COMNTOOLS
- 视觉工作室 2017:
VS150COMNTOOLS
回答by Patrick
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
回答by Scott C
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 .Netinstalled regasm.
我真的不喜欢硬编码路径以获得 regasm,当您安装新的 .Net 或在具有不同版本的机器上运行时,您需要确保找到 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 (i.e. command prompt), just use %a
instead of %%a
在 bat 文件(即命令提示符)之外,只需使用%a
代替%%a
回答by Manohar Reddy Poreddy
Execute only 1 of the below
Once a command works, skip the rest/ below to it:
只执行下面的 1
个命令运行后,跳过下面的其余部分:
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
回答by OldProgrammer
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.
通过将 dll 拖放到“regasm”上,您可以注册它。您可以打开两个“窗口资源管理器”窗口。一个将包含您要注册的 dll。第二个窗口将是“regasm”应用程序的位置。在两个窗口中向下滚动,以便您可以同时查看 dll 和“regasm”。它有助于减小两个窗口的大小,使它们并排。确保将 dll 拖到标有“应用程序”的“regasm”上。有几个“regasm”文件,但您只需要该应用程序。
回答by Jiminion
For the 64-bit RegAsm.exe you will need to find it someplace like this:
对于 64 位 RegAsm.exe,您需要在以下位置找到它:
c:\Windows\Microsoft.NET\Framework64\version_number_stuff\regasm.exe