JC.*_*JC. 570 build-process visual-studio
如何将后期构建事件限制为仅针对一种类型的构建运行?我正在使用事件将DLL复制到本地IIS虚拟目录,但我不希望在发布模式下在构建服务器上发生这种情况.
Jos*_*gle 720
构建前和构建后事件作为批处理脚本运行.你可以做一个条件语句$(ConfigurationName).
例如
if $(ConfigurationName) == Debug xcopy something somewhere
Run Code Online (Sandbox Code Playgroud)
gbj*_*anb 507
仅供参考,您不需要使用转到.shell IF命令可以与圆括号一起使用:
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".
)
Run Code Online (Sandbox Code Playgroud)
Fra*_*nov 123
像平常一样添加你的帖子构建事件.然后保存项目,在记事本(或您喜欢的编辑器)中打开它,并将条件添加到PostBuildEvent属性组.这是一个例子:
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PostBuildEvent>start gpedit</PostBuildEvent>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
Ces*_*ere 105
或者(因为事件被放入批处理文件然后被调用),请使用以下内容.(在Build事件框中,不在批处理文件中):
if $(ConfigurationName) == Debug goto :debug
:release
signtool.exe ....
xcopy ...
goto :exit
:debug
' debug items in here
:exit
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您可以为任何配置创建事件,并且仍然可以使用宏来管理它,而不必将它们传递到批处理文件中并记住%1是$(OutputPath)等:
Dan*_*ker 23
从 Visual Studio 2019 开始,现代.csproj格式支持直接在Target元素上添加条件:
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Debug'">
<Exec Command="nswag run nswag.json" />
</Target>
Run Code Online (Sandbox Code Playgroud)
UI 没有提供设置方法,但Configuration如果您通过 UI 进行更改,它似乎可以安全地保留该属性。
Eri*_*sot 13
Visual Studio 2015:正确的语法是(保持在一行):
if "$(ConfigurationName)"=="My Debug CFG" ( xcopy "$(TargetDir)test1.tmp" "$(TargetDir)test.xml" /y) else ( xcopy "$(TargetDir)test2.tmp" "$(TargetDir)test.xml" /y)
Run Code Online (Sandbox Code Playgroud)
这里没有错误255.