Ste*_*per 13 c# msbuild csproj prebuild
我正在定制一个.csproj项目,在主构建之前运行一些自定义任务.但是,我根本无法执行任务.
我取消注释文件中的<Target Name="BeforeBuild" />元素.csproj并添加了一个简单的Message任务,但是当我构建时,消息没有出现在我的输出中,所以看起来任务没有运行.所以这个片段不输出消息;
清单1:没有消息出现
<Target Name="BeforeBuild">
<Message Text="About to build ORM layer" Importance="normal" />
</Target>
Run Code Online (Sandbox Code Playgroud)
但是,如果我搞砸了一些属性,我可能会.csproj完全无法执行;
清单2:MSBuild配置错误
<Target Name="BeforeBuild">
<Message Text="About to build ORM layer" XXImportance="normal" />
</Target>
Run Code Online (Sandbox Code Playgroud)
注意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.
Run Code Online (Sandbox Code Playgroud)
这表明正在解析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.
Run Code Online (Sandbox Code Playgroud)
第74行读;
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)
更新2:我正在使用C#3编译器编译VS2008,但我正在编译的项目是一个框架2.0项目.从命令行运行时(请参阅更新1),构建似乎失败,因为存在关于Microsoft.CSharp.targets指定文件的位置的混淆.
小智 20
今天遇到同样的问题,并找到了使其工作的方法.
.csproj文件中的BeforeBuild目标旨在重新定义Microsoft.Common.targets文件中定义(和引用)的目标,该文件由Microsoft.CSharp.targets文件导入,该文件又由您导入. .csproj的.
您的问题是.csproj中导入Microsoft.CSharp.targets的行是在您定义BeforeBuild目标之后.将导入行移动到BeforeBuild目标上方,一切都应该正常工作.
希望有所帮助,
Mar*_*sen 14
事件正在触发,但您可能需要在VS中更改设置:
工具 - >选项 - >项目和解决方案 - >构建和运行:
并将MSBUild详细程度设置为最小或正常.
此外,如果您通过控制台中的msbuild进行编译,您将看到该消息,而无需更改上述设置.