问题
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