代码之家  ›  专栏  ›  技术社区  ›  Steve Cooper

MS Build BEFOREBILD未启动

  •  13
  • Steve Cooper  · 技术社区  · 14 年前

    .csproj 在主生成之前运行一些自定义任务。但是,我根本无法执行任务。

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

    清单1:没有消息出现

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

    但是,如果我修改了一些属性,我可以得到 根本不执行;

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

    XXImportance

    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 已找到类,并且正在为可用属性反映该类。

    为什么任务不能执行?

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

    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 <Import> declaration is correct, and that
    the file exists on disk.
    

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

    更新2: Microsoft.CSharp.targets 已指定文件。

    3 回复  |  直到 14 年前
        1
  •  15
  •   Martin Ingvar Kofoed Jensen    14 年前

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

    工具->选项->项目和

    并将MSBUild verbosity设置为minimal或normal。

        2
  •  23
  •   Jose Lamas Ríos    12 年前

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

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

    希望有帮助,