defining a target when compiling a visual c++ project using xbuild

故事扮演 提交于 2019-12-10 23:07:44

问题


I have a visual c++ project that outputs a library and I would like to build it on Linux using xmake. I can build it in monodevelop but I want to be able to build it from a command line.

If I try building the project using "xbuild" call then I get the following error:

....ItemMinerLibMono.cproj: error : Target named 'Build' not found in the project.

I understand from the documentation that I need to add a Target named "Build" in the csproj file but I don't know how to do that. I tried importing the Microsoft.Common.targets file like this:

<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />

but then I get the error:

: error : Target 'CreateManifestResourceNames', a dependency of target 'PrepareResources', not found.

Does anybody have any idea how to successfully compile a c++ project from a command line?

Thanks, Gregor


回答1:


Add the following to you .cproj file from MonoDevelop and it will build with xbuild.

<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" Outputs="$(TargetPath)"/>

There is probably a simpler solution, but so far I have not been able to come up with one.




回答2:


You need to import Cpp targets.

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

On a Windows machine with a full Visual Studio installation, some or all of these can be found at the following locations. I've not tested these under any version of Linux with xbuild:

VS2012: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v110
VS2013: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v120
VS2015: C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140



来源:https://stackoverflow.com/questions/11134766/defining-a-target-when-compiling-a-visual-c-project-using-xbuild

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