0

In an msbuild project, how can I tell msbuild how to invoke a compiler for a language that msbuild doesn't natively support?

(For example, with make/makefiles and most other buildsystems, it's possible to say "For all sources with .xyz extension, build them by running command 'xyzc SOME_VAR_WITH_THE_COMPILER_FLAGS SOME_VAR_WITH_SOURCE_FILENAME'". How to do the equivalent for msbuild?)

Abscissa
  • 72
  • 6
  • MsBuild doesn't really _natively_ support any compiler. It's all done with imported targets, external tasks and mostly command-line tools. Run MsBuild on a C# project with the verbosity cranked up and you'll see. – Tom Blodget Mar 19 '15 at 01:50
  • Right. By "natively" I just meant "out-of-the-box support". – Abscissa Mar 24 '15 at 15:58

1 Answers1

1

It is not hard:

<ItemGroup>
  <XyzzyFiles Include="*.xyz"/>
</ItemGroup>

<Target Name="Build">
  <Exec Command="MyCompiler %(XyzzyFiles.FullPath)"/>
</Target>

In this sample MyCompiler will be sequentially called for each .xyz file.

If you want to make single call to MyCompiler, passing list of files, use

<Target Name="Build">
  <Exec Command="MyCompiler @(XyzzyFiles->'%(FullPath)', ' ')"/>
</Target>
Nikerboker
  • 764
  • 7
  • 14
  • Thanks, although it looks like that wouldn't handle the various options, such as define symbols, debug-vs-release, etc. I realize those may need translation depending on the exact compiler in question (And I can handle that in a custom command-line util if I need to), but assuming the target compiler is command-line compatible with C#, how could that be handled? I don't suppose it would be as simple as some sort of %(AllCompilerCommandLineArguments)? – Abscissa Mar 16 '15 at 23:16
  • Of course, handling all options is not easy, but possible: Microsoft compilers are also called by MSBuild (examine Microsoft.CppCommon.targets file for example). – Nikerboker Mar 17 '15 at 18:14