问题描述
我正在执行以下操作:
- 我创建了一个默认的班级文件项目
- 编辑了csproj文件,使其包含Pre和Post BuildEvents
- 取消注释默认注释掉的BeforeBuild和AfterBuild目标
在Visual Studio中,BeforeBuild和AfterBuild目标没有被称为form,而是从msbuild命令行中获取的,为什么?
The BeforeBuild and AfterBuild targets are not called form within Visual Studio but are from msbuild command line, why is that?
我宁愿使用msbuild目标,也不愿使用PostBuildEvent,如果它可以工作的话,似乎可以给我带来更多的功能和灵活性.
I would rather use msbuild targets rather than the PostBuildEvent as if gives me more power and flexibility, assuming it works.
干杯
adam
我缩短了输出中的某些路径,所以如果它们不一致,这就是原因
ClassLibrary1.csproj更改
ClassLibrary1.csproj changes
<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生成的构建输出是
my build output from VS 2010 is
------ 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中看不到它们.
Your build events are firing, you're just not seeing them in Visual Studio.
默认情况下,VS将msbuild的详细程度设置为minimal
.您可以通过将邮件重要性更改为high
By default VS sets the msbuild verbosity to minimal
. You can get your message to show by changing the message importance to high
<Target Name="BeforeBuild">
<Message Text="### BeforeBuild ###" Importance="high" />
</Target>
<Target Name="AfterBuild">
<Message Text="### AfterBuild ###" Importance="high" />
</Target>
您还可以在VS中的工具"->选项"下,然后在项目和解决方案"->构建和运行"下更改详细度设置.
You can also change the verbosity setting in VS under Tools->Options then under Projects and Solutions->Build and Run.
这篇关于Visual Studio中的BeforeBuild和AfterBuild Target无法触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!