Visual Studio中的Before和AfterBuild目标未触发 [英] Before and AfterBuild Target in Visual Studio not firing

查看:17
本文介绍了Visual Studio中的Before和AfterBuild目标未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做以下事情:

  • 我已经创建了一个默认的类文件项目
  • 编辑了 csproj 文件以包含 Pre 和 Post BuildEvents
  • 取消注释默认的 BeforeBuild 和 AfterBuild 目标

BeforeBuild 和 AfterBuild 目标在 Visual Studio 中不是称为表单,而是来自 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.

干杯,

亚当

我缩短了输出中的一些路径,所以如果它们不一致,那就是原因

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:ClassLibrary1inDebugClassLibrary1.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:inDebugClassLibrary1.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 中的 Tools->Options 然后在 Projects and Solutions->Build and Run 下更改详细设置.

You can also change the verbosity setting in VS under Tools->Options then under Projects and Solutions->Build and Run.

这篇关于Visual Studio中的Before和AfterBuild目标未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆