How to run Visual Studio post-build events for deb

2019-01-03 07:21发布

How can I limit my post-build events to running only for one type of build? I'm using the events to copy DLLs to a local IIS virtual directory but I don't want this happening on the build server in release mode.

9条回答
smile是对你的礼貌
2楼-- · 2019-01-03 07:47

In VS 2012 you have to use (I think in VS 2010, too)

if $(Configuration) == Debug xcopy

$(ConfigurationName) was listed as a macro, but wasn't assigned.

enter image description here

Compare: http://msdn.microsoft.com/en-us/library/c02as0cs(v=vs.110).aspx

查看更多
Summer. ? 凉城
3楼-- · 2019-01-03 07:56

alternatively (since the events are put into a batch file & then called), use the following. (in the Build event box, not in a batch file):

if $(ConfigurationName) == Debug goto :debug

:release
signtool.exe ....
xcopy ...

goto :exit

:debug
' debug items in here

:exit

This way you can have events for any configuration, and still manage it with the macros rather than having to pass them into a batch file & remember that %1 is $(OutputPath) etc:

查看更多
女痞
4楼-- · 2019-01-03 08:00

Add your post build event like normal. Then save you project, open it in Notepad (or your favorite editor) and add condition to the PostBuildEvent property group. Here's an example:

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <PostBuildEvent>start gpedit</PostBuildEvent>
</PropertyGroup>
查看更多
时光不老,我们不散
5楼-- · 2019-01-03 08:01

Pre- and Post-Build Events run as a batch script. You can do a conditional statement on $(ConfigurationName).

For instance

if $(ConfigurationName) == Debug xcopy something somewhere
查看更多
Melony?
6楼-- · 2019-01-03 08:05

You can pass the configuration name to the post-build script and check it in there to see if it should run.

Pass the configuration name with $(ConfigurationName)

Checking it is based on how you are implementing the post-build step -- it will be a command-line argument

查看更多
对你真心纯属浪费
7楼-- · 2019-01-03 08:10

FYI, you do not need to use goto. the shell IF command can be used with round brackets:

if $(ConfigurationName) == Debug (
  copy "$(TargetDir)myapp.dll" "c:\delivery\bin" /y
  copy "$(TargetDir)myapp.dll.config" "c:\delivery\bin" /y
) ELSE (
  echo "why, Microsoft, why".
)
查看更多
登录 后发表回答