MS-Build BeforeBuild 未触发

MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)
本文介绍了MS-Build BeforeBuild 未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在自定义一个 .csproj 项目以在主构建之前运行一些自定义任务.但是,我根本无法执行任务.

I'm customising a .csproj project to run some custom tasks before the main build. However, I can't get the tasks to execute at all.

我取消了 .csproj 文件中的 <Target Name="BeforeBuild"/> 元素的注释并添加了一个简单的消息任务,但是当我构建时,消息没有出现在我的输出中,因此任务似乎没有运行.所以这个片段不输出消息;

I uncommented the <Target Name="BeforeBuild" /> element in the .csproj file and added a simple Message task, but when I build, the message doesn't appear in my output, so it seems the task isn't running. So this fragment does not output the message;

清单 1:没有消息出现

<Target Name="BeforeBuild">
    <Message Text="About to build ORM layer" Importance="normal" />
</Target>

但是,如果我搞砸了一些属性,我可以让 .csproj 根本无法执行;

However, if I screw with some of the attributes, I can get the .csproj to fail to execute at all;

清单 2:MSBuild 配置错误

<Target Name="BeforeBuild">
    <Message Text="About to build ORM layer" XXImportance="normal" />
</Target>

注意 XXImportance 属性.我得到的构建错误是

Note the XXImportance attribute. The build error I get is

My.csproj(83,46): error MSB4064: The "XXImportance" parameter is not supported by the "Message" task. Verify the parameter exists on the task, and it is a settable public instance property.

这表明正在解析 XML,已找到 Message 类,并且正在反映该类以获取可用属性.

This suggests that the XML is being parsed, that the Message class has been found, and that the class is being reflected over for the available properties.

为什么任务不执行?

我使用的是 3.5 框架.

I'm using the 3.5 framework.

更新 1: 在 @Martin 的建议下,我尝试在控制台上运行 MSBuild,但出现此错误;

UPDATE 1: On @Martin's advice, I tried to run MSBuild on the console, and got this error;

c:path	omy.csproj(74,11): error MSB4019: The imported
project "C:Microsoft.CSharp.targets" was not found. Confirm
that the path in the <Import> declaration is correct, and that
the file exists on disk.

第 74 行读取;

<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />

更新 2: 我在 VS2008 中编译,它使用 C#3 编译器,但我正在编译的项目是框架 2.0 项目.从命令行运行时(参见更新 1),构建似乎失败了,因为对于 Microsoft.CSharp.targets 文件的指定位置存在混淆.

UPDATE 2: I'm compiling in VS2008, which uses the C#3 compiler, but the project I'm compiling is a framework 2.0 project. When run from the command line (see UPDATE 1) the build seems to fail because there is a confusion as to where the Microsoft.CSharp.targets file is specified.

推荐答案

事件正在触发,但您可能需要更改 VS 中的设置:

The event is firing, but you might need to change your settings in VS:

工具->选项->项目和解决方案->构建并运行:

Tools->Options->Projects and Solutions->Build and Run:

并将 MSBUild 详细程度设置为最小或正常.

And set MSBUild verbosity to minimal or normal.

此外,如果您在控制台中通过 msbuild 进行编译,您将看到该消息,而无需更改上述设置.

Also, if you compile through msbuild in the console you will see the message without having to change the above settings.

这篇关于MS-Build BeforeBuild 未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
Using C# 7.1 with MSBuild(将 C# 7.1 与 MSBuild 结合使用)