简体   繁体   中英

How to register a DLL with RegAsm in Build EventS VS2013

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

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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