Tuesday, June 12, 2012

Visual Studio Post-Build GacUtil.exe with error handling

If you have ever had to deploy a solution to the GAC then you will love this Post-Build Command.


I found the original here by Dave Chestnutt and made it work for me:



echo POSTBUILDSTEP for $(ProjectName)
xcopy "$(TargetPath)" "$(SolutionDir)$(OutDir)" /i /d /y
if errorlevel 1 goto BuildEventFailed
xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)$(OutDir)" /i /d /y
if errorlevel 1 goto BuildEventFailed 
echo GAC of: "$(SolutionDir)$(OutDir)$(TargetFileName)"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\gacutil.exe" /i $(TargetPath)"
if errorlevel 1 goto BuildEventFailed 
REM Exit properly because the build will not fail 
REM unless the final step exits with an error code
goto BuildEventOK
:BuildEventFailed
echo POSTBUILDSTEP for $(ProjectName) FAILED
exit 1
:BuildEventOK
echo POSTBUILDSTEP for $(ProjectName) COMPLETED OK

No comments:

Post a Comment