I'm trying to auto sign project with certificate using signtool.exe in Visual Studio 2010. Here is my simplified post-build script:
if $(ConfigurationName) == Debug ( call "$(VS100COMNTOOLS)VCVarsQueryRegistry.bat" call "$(WindowsSdkDir)bin/signtool.exe" sign /f "$(ProjectDir)my.pfx" /p mypass /t timstamp.dll "$(TargetPath)" )
Debug
is for testing purposes. I'm trying to mimic Visual Studio command prompt
- execute $(VS100COMNTOOLS)VCVarsQueryRegistry.bat
which adds some extra variables and then use it later. $(WindowsSdkDir)
is what I need.
While that script works perfectly in simple bat
file it refuses to work in Visual Studio. Output is:
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\VCVarsQueryRegistry.bat" call "bin/signtool.exe" sign ...
Notice that it doesn't recognize $(WindowsSdkDir), which is created in VCVarsQueryRegistry.bat.
Is it possible to declare var in bat and use it later in post-build or I should use another approach?
It's a bit tricky:
%var%
syntax instead of msbuild-like $(var)
call
batches do apply.. but if
body precalculates its variables, so you need several if
lines instead of just one if
body. Here is good explanation of such behavior and other ways to avoid it Weird scope issue in .bat file So, this one should work:
if $(ConfigurationName) == Debug call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat"
if $(ConfigurationName) == Debug call "%WindowsSdkDir%bin\signtool.exe" sign /f "$(ProjectDir)my.pfx" /p mypass /t timstamp.dll "$(TargetPath)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With