1

I am trying to perform registration of the DLL which was created during Build.

In project properties -> Build Events -> Post-Build-Event i have added the below command to perform registration,

regsvr32 /s /c "$(TargetPath)"

Post-Build-Event Dialog

This command is used to perform registration of the DLL specified in Target Path. When i try to Build my code, i am facing following error,

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(138,5): 

error MSB3073: The command "regsvr32 /s /c "D:\Project\Debug\x64\SDK.dll"

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(138,5): 

error MSB3073: :VCEnd" exited with code 3.

On clicking the error, it navigates to below tags within Microsoft.CppCommon.targets

 <Target Name="PostBuildEvent" Condition="'$(PostBuildEventUseInBuild)'!='false'">
<Message Text="%(PostBuildEvent.Message)" Condition="'%(PostBuildEvent.Message)' != '' and '%(PostBuildEvent.Command)' != ''" Importance="High" />
<Exec Command="%(PostBuildEvent.Command)$(_BuildSuffix)" Condition="'%(PostBuildEvent.Command)' != ''"/>

I searched for error MSB3073: :VCEnd" exited with code 3 in few links and found that it occurs when the path specified is invalid or could not be found.

However, the path of the DLL was in the location i specified. I even tried to provide absolute path of DLL within the Post-Build-Event. Yet i'm facing same error.

Am i missing something while performing Post-Build-Event or is there anything to do with regsvr32 command?

Sharath Kumar
  • 73
  • 1
  • 9
  • That's not the problem, but the `regsvr32 /c` switch hasn't worked since NT4 times. – dxiv Jul 28 '20 at 17:15
  • I think your dll project is dynamic library project and the project does not have ID. When you want to register a dll, you should make sure that the project has ID. So this type of project cannot be used as DLLs that will to be registered. – Mr Qian Jul 29 '20 at 08:05
  • You can try to use ATL projects as dll projects and you can check my answer. – Mr Qian Jul 29 '20 at 08:17
  • @PerryQian-MSFT Hi, Thanks for the answer. Seems like issue is w.r.t COM dll being used and additional library dependencies which are not linked to COM dll as expected. The project is too old and is in optimisation phase. Here, we need to use already implemented DLL project to resolve this issue. Also we could find few legacy issues as you mentioned. I would try implementing DLLRegisterServer and check if the issue could be resolved. Thank you – Sharath Kumar Jul 30 '20 at 06:28
  • 1
    @SharathKumar, any update about this issue? Since your old project is wrt com project, I suggest you could create a new one in VS2017(the new one has been updated in VS2017 and works well with the command). Then migrate your old project into it. It can save you a lot of time and avoid several errors. – Mr Qian Jul 31 '20 at 03:31
  • @SharathKumar, I have updated my answer and you can check `update 1`. – Mr Qian Jul 31 '20 at 03:31
  • Thank you soo much for the response. We will look into this and come back with our view. – Sharath Kumar Jul 31 '20 at 05:16
  • This old project worked fine (Successful DLL registration) when we opened it's solution directly from VS2017 and built it. However, the project should work in both Windows and Linux platform. In order to make this platform independent, we changed the Multi-thread implementation by adding pthread library. We are facing the registration issue after adding this library dependency. Without pthread dependency, registration is successful for the old command I specified. – Sharath Kumar Jul 31 '20 at 05:24
  • Okay! Thanks for sharing the useful info. Maybe sharing a small sample of your project with us would be helpful. When I install the [pthread nuget package](https://www.nuget.org/packages/pthreads/) in my side--- VS2017 project. And it could also build well. Maybe I lack something that needs to be pointed out. – Mr Qian Jul 31 '20 at 08:22

1 Answers1

1

MSB3073 exited with code 3 - Post Build Event in Visual Studio 2017

The issue is related to your dynamic library project and not related to VS.

And when you want to register a com dll, the dll project should contain a ID to register into system. However, the dynamic library project does not have the ID by default. So this type of project cannot used as DLLs that will to be registered.

If you still want to use dynamic library project, you should implement DllRegisterServer to add the ID.

You can use ATL projects which contain the ID as dll projects .

This is a similar issue about it.

Solution

1) Instead, you should create ATL projects.

2) Then, in the command, you should remove /c which was abandoned so far.

Or use like this command:

regsvr32 /n /i "$(TargetPath)" as command in post-build event.

=====================

Update 1

Since your project is an old WRT project, you can just create a new WRT runtime component project in VS2017 and then migrate the content of your old project into the new one. It will save you a lot of time and avoid a lot of tedious mistakes.

1) Please install C++/WinRT vs extension first.

2) Then create a new windows runtime componment project and then migrate your old project's content into the new one.

enter image description here

In my side, the project can works well with command regsvr32 /n /i "$(TargetPath)".

Mr Qian
  • 21,064
  • 1
  • 31
  • 41