我有一个Web项目,用于触发构建后事件“成功构建”以执行一些清理/迁移活动(命令脚本)。
在VS2012中,成功后构建仅在代码更改时触发。如果没有代码更改,编译器仍会报告Successful Build,但是,成功后构建事件不会触发。
在VS2010中,无论代码更改如何,每次成功构建时都会触发成功后构建事件。这就是我所期待的。编译成功,即使没有发生任何变化,因此该事件应该触发。
使用代码更改的VS2012构建示例:
------ Build started: Project: ABC.Business.Web.Migrate, Configuration: Debug Any CPU ------
Build started 2012-08-23 01:26:13.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva- /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /debug+ /debug:full /optimize- /out:obj\Debug\ABC.Web.Migrate.dll /target:library /utf8output Properties\AssemblyInfo.cs "C:\Users\Administrator\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
_CopyFilesMarkedCopyLocal:
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll" to "bin\ABC.Business.Web.dll".
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Web.dll" to "bin\ABC.Web.dll".
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC._Services.dll" to "bin\ABC._Services.dll".
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.pdb" to "bin\ABC.Business.Web.pdb".
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Web.pdb" to "bin\ABC.Web.pdb".
Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC._Services.pdb" to "bin\ABC._Services.pdb".
CopyFilesToOutputDirectory:
Copying file from "obj\Debug\ABC.Web.Migrate.dll" to "bin\ABC.Web.Migrate.dll".
ABC.Business.Web.Migrate -> C:\Dev\ABC\Source\ABC.Business.Web.Migrate\bin\ABC.Web.Migrate.dll
Copying file from "obj\Debug\ABC.Web.Migrate.pdb" to "bin\ABC.Web.Migrate.pdb".
PostBuildEvent:
"C:\Dev\bin\spawn.exe" "C:\Dev\ABC\Scripts\Migrate Business Web.bat"
Build succeeded.
Time Elapsed 00:00:00.34
========== Build: 4 succeeded, 0 failed, 53 up-to-date, 0 skipped ==========
没有代码更改的VS2012构建示例:
------ Build started: Project: ABC.Business.Web, Configuration: Debug Any CPU ------
Build started 2012-08-23 01:36:04.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
ABC.Business.Web -> C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll
Build succeeded.
Time Elapsed 00:00:00.31
========== Build: 1 succeeded, 0 failed, 56 up-to-date, 0 skipped ==========
我尝试在VS2012中使用post-build事件“Always”。如果代码更改(仅与On成功相同),它仅触发Always post-build事件。我唯一的解决方法是进行重建 - 当我有几十个依赖项目时会很痛苦!或者手动运行我的脚本 - 也很烦人! (并且不,这不是我的脚本 - 当第一个示例说明代码更改时,此脚本可以正常工作!)
这可能是故意更改或错误。
还有其他人在VS2012中遇到过这个构建后的问题吗?
答案 0 :(得分:30)
我遇到了同样的问题,我解决了以下问题:
就是这样,它将始终执行de POST-BUILD步骤,即使项目是最新的或不是启动项目。
答案 1 :(得分:1)
我有类似的问题,这对我有帮助:
工具......选项......项目和解决方案......构建和运行......
取消选中“仅在运行时构建启动项目和依赖项”
答案 2 :(得分:1)
对我来说,我需要this answer,其中说明如果您正在调用批处理文件,请使用:
CALL mybatch
CALL anothercommand
而不是直接使用命令:
mybatch
anothercommand
如果未使用mybatch
,则只会调用CALL
。
答案 3 :(得分:0)
如果在导入Sys.getenv("X13_PATH")
之前定义了PostBuildEvent
属性,则构建后事件可能无法正常运行。确保定义post build事件的$(MSBuildToolsPath)\Microsoft.CSharp.targets
是在导入此文件之后。
错误的msbuild文件示例:
<PropertyGroup>
正确的msbuild文件示例:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Snip -->
<!-- DO NOT USE, INCORRECT ORDERING OF IMPORT -->
<PropertyGroup>
<PostBuildEvent>echo $(TargetName)</PostBuildEvent>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>