[Mono-dev] building for Mono under msbuild

Marek Sieradzki marek.sieradzki at gmail.com
Wed Oct 12 12:31:37 EDT 2005


Dnia 11-10-2005, wto o godzinie 11:49 -0700, Andy Waddell napisał(a):
> I have an application that needs to run under both .NET and Mono and I
> came up with a pretty simple way to get MS DevStudio to build both.  I
> don’t know how others have solved this problem, but I thought I would
> offer it up in case it helps someone else with the same issue.  The
> basic approach I took was to call the Mono compiler after the
> Microsoft build has already run.  Microsoft has a well known target
> “AfterBuild” which I have hooked to invoke gmcs with pretty much the
> same arguments that csc.exe takes with some minor modifications.  I
> put all the Mono build stuff in a file called Mono.targets, so it only
> take a one line addition to the standard *.csproj file to get the
> functionality:
> 
>  
> 
>   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
> 
> Add this lineà  <Import Project="<your path>\Mono.targets" />

Few weeks before this post someone sent post with his .targets file. It
should be in the archive. (I don't know if attachment is also archived)

> This will make your build essentially a dual pass build with all the
> Microsoft stuff running and then the Mono compiler running with all
> the warnings and erros showing up in the IDE as you would expect.  The
> work is not complete (I don’t pass all the options possible, etc), but
> I think it’s fairly obvious how to expand it if needed.  
> 
>  
> 
> I’m sure there are many other ways to skin this cat, but for a quick
> and dirty solution, it seems to work pretty well.  
> 
>  
> 
> ToDo: invesitgate xbuild to do my Linux builds.
> 

Current xbuild won't build project from .csproj file because some
features use by Microsoft.Common.targets are not implemented and because
of that this .targets file is not made for Mono but Microsoft .NET
runtime.

At this moment it should be possible to use mcs by
Microsoft.Build.Tasks.Csc from xbuild. You would need to load it
(UsingTask) and create your own version of Compile target. You need to
be sure that VS does not use
HostObject(Microsoft.Build.Tasks.Hosting.ICscHostObject) compiler which
is implemented in VS2005 but not in MSBuild or xbuild.

I'm working on rewrite in xbuild. When I'll get some free time I'll
write more tests and fix bugs. (like AL task that isn't reporting
errors/warnings properly)

-- 
Marek Sieradzki <marek.sieradzki at gmail.com>




More information about the Mono-devel-list mailing list