MS-Build BeforeBuild 未触发

发布于 2024-09-11 13:50:27 字数 1510 浏览 10 评论 0原文

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

我取消了 .csproj 文件中的 元素的注释,并添加了一个简单的消息任务,但是当我构建时,该消息没有没有出现在我的输出中,所以任务似乎没有运行。所以这个片段不会输出消息;

清单 1:没有消息出现

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

但是,如果我修改某些属性,我可能会导致 .csproj 根本无法执行;

清单 2:MSBuild 配置错误

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

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

My.csproj(83,46):错误 MSB4064:“消息”任务不支持“XXImportance”参数。验证该参数存在于任务中,并且它是可设置的公共实例属性。

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

为什么任务无法执行?

我使用的是3.5框架。

更新1:根据@Martin的建议,我尝试在控制台上运行MSBuild,并收到此错误;

c:\path\to\my.csproj(74,11): 错误 MSB4019: 导入的 项目“C:\Microsoft.CSharp.targets”未找到。确认 声明中的路径是正确的,并且 该文件存在于磁盘上。

第 74 行如下:

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

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

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

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;

Listing 1: No Message Appears

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

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

Listing 2: An MSBuild configuration error

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

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.

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.

Why would the task not execute?

I'm using the 3.5 framework.

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

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

Line 74 reads;

<Import Project="$(MSBuildToolsPath)\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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声情话 2024-09-18 13:50:27

今天遇到了同样的问题,找到了解决方法。

.csproj 文件中的 BeforeBuild 目标旨在重新定义 Microsoft.Common.targets 文件中定义(和引用)的目标,该文件由 Microsoft.CSharp.targets 文件导入,而 Microsoft.CSharp.targets 文件又由您的 Microsoft.CSharp.targets 文件导入。 .csproj。

您的问题是 .csproj 中导入 Microsoft.CSharp.targets 的行位于 BeforeBuild 目标的定义之后。将导入行移至 BeforeBuild 目标上方,一切都应该正常工作。

希望有帮助,

Had the same problem today and found the way to make it work.

The BeforeBuild target in your .csproj file is intended to be a redefinition of a target defined (and referenced) in the Microsoft.Common.targets file, which is imported by the Microsoft.CSharp.targets file, which in turn is imported by your .csproj.

Your problem is that the line in your .csproj that imports Microsoft.CSharp.targets is after your definition of the BeforeBuild target. Move the import line to above your BeforeBuild target and everything should work fine.

Hope that helps,

与君绝 2024-09-18 13:50:27

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

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

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

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

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

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

And set MSBUild verbosity to minimal or normal.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文