我有一个web项目,它会在“成功构建时”触发一个构建后事件来执行一些清理/迁移活动(命令脚本)。
在VS2012中,post-build on success仅在代码更改时触发。如果没有代码更改,编译器仍会报告生成成功,但不会触发生成成功后的事件。
在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中“总是”使用构建后事件。它仅在发生代码更改时才会触发Always post-build事件(与On success相同)。我唯一的解决办法就是重建--当我有几十个依赖的项目时,这是一件痛苦的事情!或者手动运行我的脚本--也很烦人!(不,这不是我的脚本--当有代码更改时,这个脚本工作得非常好,正如第一个示例所示!)
这要么是故意的更改,要么是一个bug。
还有没有人在VS2012中遇到过这种构建后的问题?
发布于 2012-10-20 02:00:33
我遇到了类似的问题,这对我很有帮助:
工具...选项...项目和解决方案...构建并运行...
取消选中“只在运行时生成启动项目和依赖项”
发布于 2016-08-19 03:46:19
如果在导入$(MSBuildToolsPath)\Microsoft.CSharp.targets
之前定义了PostBuildEvent
属性,则生成后事件可能无法正确运行。确保定义构建后事件的<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>
正确的msbuild文件示例:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Snip -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>echo $(TargetName)</PostBuildEvent>
</PropertyGroup>
</Project>
发布于 2016-11-23 01:29:25
对于我来说,我需要this answer,它说明如果你正在调用一个批处理文件,那么使用:
CALL mybatch
CALL anothercommand
而不是直接使用命令:
mybatch
anothercommand
如果不使用CALL
,则只会调用mybatch
。
https://stackoverflow.com/questions/12084133
复制相似问题