我正在执行以下操作:
我创建了一个默认的类文件项目
编辑了csproj文件以包括Pre和Post BuildEvents
取消注释默认注释掉的BeforeBuild和AfterBuild目标
在Visual Studio中,BeforeBuild和AfterBuild目标未称为form,而是从msbuild命令行调用的,为什么?
我宁愿使用msbuild目标,也不愿使用PostBuildEvent,如果它可以工作的话,似乎可以给我带来更多功能和灵活性。
干杯,
亚当
我缩短了输出中的某些路径,所以如果它们不一致,这就是为什么
ClassLibrary1.csproj更改
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BeforeBuild">
<Message Text="### BeforeBuild ###" />
</Target>
<Target Name="AfterBuild">
<Message Text="### AfterBuild ###" />
</Target>
<PropertyGroup>
<PreBuildEvent>echo PRE_BUILD</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>echo POST_BUILD</PostBuildEvent>
</PropertyGroup>
我从VS 2010生成的输出是
------ Rebuild All started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
PRE_BUILD
ClassLibrary1 -> c:\ClassLibrary1\bin\Debug\ClassLibrary1.dll
POST_BUILD
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
并从命令行
#>msbuild ClassLibrary1.sln
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.239]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 09/05/2012 13:27:42.
Project "c:.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "c:.sln" (1) is building "c:\ClassLibrary1.csproj" (2) on node 1 (default targets).
BeforeBuild:
### BeforeBuild ###
PreBuildEvent:
echo PRE_BUILD
PRE_BUILD
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:
ClassLibrary1 -> c:\bin\Debug\ClassLibrary1.dll
PostBuildEvent:
echo POST_BUILD
POST_BUILD
AfterBuild:
### AfterBuild ###
Done Building Project "c:\ClassLibrary1.csproj" (default targets).
Done Building Project "c:.sln" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.18
最佳答案
您的构建事件正在触发,您只是在Visual Studio中看不到它们。
默认情况下,VS将msbuild的详细程度设置为minimal
。您可以通过将消息的重要性更改为high
来显示消息
<Target Name="BeforeBuild">
<Message Text="### BeforeBuild ###" Importance="high" />
</Target>
<Target Name="AfterBuild">
<Message Text="### AfterBuild ###" Importance="high" />
</Target>
您也可以在VS中的“工具”->“选项”下,然后在“项目和解决方案”->“构建并运行”下更改详细设置。