How to register a DLL with RegAsm in Build EventS VS2013

天涯浪子 提交于 2021-02-10 08:43:52

问题


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 ?

My dll location : C:\Program Files (x86)\Onur\Client\Bin\client.dll

My regasm location : 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 ?

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


回答1:


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

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.

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)"

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

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.



来源:https://stackoverflow.com/questions/37854287/how-to-register-a-dll-with-regasm-in-build-events-vs2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!