To Digitally Sign a Binary (ObjectARX or Managed .NET) File with a Post-Build Event in Microsoft Visual Studio

A post-build event is an action that occurs after a project has been built. You can use a post-build event to digitally sign a binary (ObjectARX or Managed .NET) file after it has been built. The following steps explain how to add a post-build event that uses the SignTool.exe tool from the Windows SDK to digitally sign the target file of a project.

For more information on using the SignTool.exe tool, see "To Digitally Sign a Binary (ObjectARX or Managed .NET) File."

Note: Special characters in a project name or folder path can cause problems with the SignTool.exe tool or other programs being executed as part of a post-build event.

Visual Basic

  1. In Microsoft Visual Studio, Solution Explorer, right-click a project and choose Properties.
  2. On the Properties page, click the Compile tab.
  3. Scroll to the bottom of the page and click Build Events.
  4. In the Build Events dialog box, click Edit Post-build.
  5. In the Post-Build Event Command Line dialog box, type the statement that executes the SignTool.exe tool and the arguments that it should use.

    The following shows an example of signing the target file of the project with a password protected digital certificate stored in the MyCert.pfx file under the Autodesk folder:

    "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "C:\Autodesk\MyCert.pfx" /p MyPassword "$(TargetDir)$(TargetFileName)"
    Tip: Click Macro to add macros to the command-line statements to execute.

    $(TargetDir) and $(TargetFileName) are macros that allow you to dynamically specify the build target folder and file name as part of the command-line programs to execute as part of the post-build event.

  6. Click OK to close the Post-Build Event Command Line dialog box.
  7. In the Build Events dialog box, click the Run The Post-build Event drop-down list and select On Successful Build.
  8. Click OK to save the post-build event.
  9. Rebuild the project to test the post-build-event.

    The Output window will display information about whether the post-build event completed successfully.

    PostBuildEvent:
      "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "C:\Autodesk\MyCert.pfx" /p MyPassword "C:\Autodesk\AdskUtils\bin\x64\Release\AdskUtils.dll"
      Done Adding Additional Store
      Successfully signed: C:\Autodesk\AdskUtils\bin\x64\Release\AdskUtils.dll

Visual C#

  1. In Microsoft Visual Studio, Solution Explorer, right-click a project and choose Properties.
  2. On the Properties page, click the Build Events tab.
  3. Scroll to the bottom of the page and click Edit Post-build.
  4. In the Post-Build Event Command Line dialog box, type the statement that executes the SignTool.exe tool and the arguments that it should use.

    The following shows an example of signing the target file of the project with a password protected digital certificate stored in the MyCert.pfx file under the Autodesk folder:

    "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "C:\Autodesk\MyCert.pfx" /p MyPassword "$(TargetDir)$(TargetFileName)"
    Tip: Click Macro to add macros to the command-line statements to execute.

    $(TargetDir) and $(TargetFileName) are macros that allow you to dynamically specify the build target folder and file name as part of the command-line programs to execute as part of the post-build event.

  5. Click OK to close the Post-Build Event Command Line dialog box.
  6. On the Properties page, click the Run The Post-build Event drop-down list and select On Successful Build.
  7. Rebuild the project to test the post-build-event.

    The Output window will display information about whether the post-build event completed successfully.

    PostBuildEvent:
      "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "C:\Autodesk\MyCert.pfx" /p MyPassword "C:\Autodesk\AdskUtils\bin\x64\Release\AdskUtils.dll"
      Done Adding Additional Store
      Successfully signed: C:\Autodesk\AdskUtils\bin\x64\Release\AdskUtils.dll

Visual C++

  1. In Microsoft Visual Studio, Solution Explorer, right-click a project and choose Properties.
  2. In the Property Page dialog box, click the Configuration drop-down list and select All Configurations.
  3. Expand the Configuration Properties Build Events and click Post-Build Event.
  4. On the Post-Build Event page, click the Command Line field. Click the drop-down list and select <Edit...>.
  5. In the Command Line dialog box, type the statement that executes the SignTool.exe tool and the arguments that it should use.

    The following shows an example of signing the target file of the project with a password protected digital certificate stored in the MyCert.pfx file under the Autodesk folder:

    "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "C:\Autodesk\MyCert.pfx" /p MyPassword "$(TargetDir)$(TargetFileName)"
    Tip: Click Macro to add macros to the command-line statements to execute.

    $(TargetDir) and $(TargetFileName) are macros that allow you to dynamically specify the build target folder and file name as part of the command-line programs to execute as part of the post-build event.

  6. Click OK to close the Command Line dialog box.
  7. On the Property Page, click the Use In Build field. Click the drop-down list and select Yes.
  8. Click OK to save the post-build event.
  9. Rebuild the project to test the post-build-event.

    The Output window will display information about whether the post-build event completed successfully.

    1>PostBuildEvent:
    1>  Done Adding Additional Store
    1>  Successfully signed: C:\Autodesk\AdskUtils\bin\x64\Release\AdskUtils.arx