如何在Build EventS VS2013中使用RegAsm注册DLL [英] How to register a DLL with RegAsm in Build EventS VS2013

查看:71
本文介绍了如何在Build EventS VS2013中使用RegAsm注册DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每次编译中,输出dll在我的程序中都会更改,并且在每次编译后,我必须再次注册dll.我可以通过 Visual Studio命令提示符将其注册为 regasm mydll.dll.但是我不想每次都这样做,我希望它能自动运行.经过一番研究,我发现 Build Events (项目>属性)中的Visual Studio可以实现.但是我以前从未使用过构建事件,而且我真的不知道它会如何.我应该将dll路径写入构建前事件命令行吗?

In every compile, output dll is changed in my program and after every compile, I must register dll again. I can register it via Visual Studio Command Prompt as regasm mydll.dll. But I dont want to do it everytime and I want it as automatically. After some research, I have detected that it is possible with Visual Studio from Build Events (project>properties). But I have never used Build Events before and I really cannot understand how it will be. Should I write my dll path to pre-build event command line ?

我的dll位置: C:\ Program Files(x86)\ Onur \ Client \ Bin \ client.dll

我的加气位置: C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ RegAsm.exe

我应该在构建事件"部分中为构建前和构建后命令写些什么?

What should I write to pre-build and post-build commands in Build Events section ?

我尝试了它们,但甚至没有在其中进行编译. VS生成后事件

I tried them but even not compiled within it. VS Post Build Event

推荐答案

RegAsm可执行文件位于.Net Framework版本文件夹中,但默认情况下不在您的路径中.

The RegAsm executable is located in the .Net Framework version folder but that is not by default in your path.

幸运的是,您可以在构建后事件中使用两个环境变量,即 FrameworkDir FrameWorkVersion .MSDN文档说明了如何使用环境变量.

Fortunately there exist two Environment variables, namely FrameworkDir and FrameWorkVersion that you could use in your Post-build event. The MSDN documentation explains how to use Environment Variables.

对于您的特定情况,以下操作在Post-Build事件中起作用(因为您的新dll需要编译并准备就绪):

For your specific case, the following does work in the Post-Build event (because your new dll need to be compiled and ready):

 $(frameworkdir)\$(frameworkversion)\regasm.exe "$(TargetPath)"

请注意如何将 $(TargetPath)用双引号引起来,以防万一您的路径中有空格.

Notice how the $(TargetPath) is enclosed in double quotes to prevent any mishaps in case there is a space in your path.

如果 frameworkdir 和/或 frameworkversion 不存在,则可以使用完整路径,但是在这种情况下,必须确保该路径在所有要使用的计算机上都存在运行该版本.您不妨决定将regasm.exe置于源代码控制之下,并将其作为您的buildtools的一部分.

If frameworkdir and/or frameworkversion don't exist you can use a fullpath but in that case you have to make sure that path exists on all machines you want to run that build. You might as well decide to bring the regasm.exe under source control and make it part of your buildtools.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "$(TargetPath)"

请记住,尽管RegAsm需要提升的权限,所以您首先需要运行已经提升的Visual Studio才能使RegAsm的执行工作正常.

Keep in mind though that RegAsm requires elevated privileges so you would need to run Visual Studio already elevated to make the execution of RegAsm work in the first place.

使用构建输出"窗格来诊断错误.

Use the Build Output pane for diagnosing errors.

这篇关于如何在Build EventS VS2013中使用RegAsm注册DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆