visual-studiovisual-c++msbuildpost-build-eventregsvr32

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


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?


Solution

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