我正在自定义一个.csproj
项目以在主构建之前运行一些自定义任务。但是,我根本无法执行任务。
我取消了文件中的<Target Name="BeforeBuild" />
元素的注释.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): 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
已找到该类,并且正在反映该类以获取可用属性。
为什么任务不执行?
我正在使用 3.5 框架。
更新 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.
第 74 行读取;
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
更新 2:我在 VS2008 中编译,它使用 C#3 编译器,但我正在编译的项目是框架 2.0 项目。从命令行运行时(请参阅更新 1),构建似乎失败了,因为Microsoft.CSharp.targets
文件的指定位置存在混淆。