Pass custom msbuild target from Solution to Project

你离开我真会死。 提交于 2020-01-02 02:41:12

问题


I have a Solution with a large number of associated .csproj files.

Each .csproj file has a <Target Name="PublishQA">....

The build fails when I try to compile the whole solution:

> msbuild mysolution.sln /t:PublishQA`
"c:\myproj.sln" (publishqa target) (1) ->
  c:\myproj.sln.metaproj : error MSB4057: The target "PublishQA" does not exist in the project. [c:\myproj.sln]

When I build the .csproj project directly, it builds just fine.

How do I tell msbuild to pass the target to the project files???


回答1:


As a case you can create seperate targets file which explicitly builds your solution,

<!-- mytargets.targets file -->
<Project ToolsVersion="4.0" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"  
         DefaultTargets="MyTargets" 
         InitialTargets="MyTargets">

    <Target Name="MyTargets">
       <MSBuild Projects="MySolution.sln" />
    </Target>

</Project>

So now you should be able just calling it like

msbuild.exe mytargets.targets



来源:https://stackoverflow.com/questions/8451799/pass-custom-msbuild-target-from-solution-to-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!