Mulitargeting C # Project Files with Mono and MonoDevelop

I have a collection of csproj files that all belong to the same set of source files but have slightly different target data, so I need to save the project files separately. For example. There are options for WinPhone, XBox, Desktop, MonoTouch of the same project.

For things that are really duplicated, such as a list of .cs files to compile, I would like to combine the list into a single file, so I do not have to constantly ensure that all options are kept in sync. I initially tried to do this by deleting the source files from .csprojs and putting them in the .targets file that was imported by all csprojs, but this made the source files disappear from VS and MonoDevelop.

My second attempt was to make the main csproj Desktop file the main one and allow all changes to import this csproj with some conditional logic. This saves the source files editable from the main csproj, and they are built in to all tastes. Visual Studio now understands what I'm trying to do, but MonoDevelop cannot create it. In the MonoDevelop solution, the iOS version of the core DLL is grayed out and says: "(not built into the active configuration)"

I also tried xbuilding csproj and a solution that seems to overcome the problems that MonoDevelop has, but hiccups on other issues related to resolving monotouch builds. I thought MonoDevelop used xbuild, but maybe not?

Since this works on Windows msbuild, it seems to be either an error or a feature not supported in Mono. Or maybe there is a better way to handle the whole scenario ... I thought I'd ask here.

For specificity, My Core.iOS.csproj file looks like this:

<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0" > <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>10.0.0</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{AE37B15F-F4BE-48DE-9F20-F00A601EC89E}</ProjectGuid> <ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <AssemblyName>Core.iOS</AssemblyName> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="monotouch" /> </ItemGroup> <Import Project=".\Core.csproj" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </Project> 

And my Core.csproj file looks like this:

 <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>Core</RootNamespace> </PropertyGroup> <!-- Using AssemblyName presence to check for whether this is imported. --> <PropertyGroup Condition=" '$(AssemblyName)' == '' "> <ProductVersion>8.0.50727</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{FC495BD8-11B1-46B0-A9DE-F245A0CBEE94}</ProjectGuid> <AssemblyName>Core</AssemblyName> <SignManifests>false</SignManifests> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <!-- properties similar to Debug --> </PropertyGroup> <ItemGroup Condition=" '$(Platform)' == 'AnyCPU' "> <Reference Include="System" /> <Reference Include="System.Core" /> </ItemGroup> <Import Condition=" '$(AssemblyName)' == 'Core' " Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> <Compile Include="[...]" /> <Compile Include="[...]" /> </Project> 

And, as I said, a variant of this seems to work correctly when using VS Express for WinPhone and XBox360 projects. Is this something that should work? Is there a better way to do this?

Thanks,

+8
mono msbuild monodevelop xbuild
source share
1 answer

Short answer:

This will not work, because although MonoDevelop uses the MSBuild file format, it does not use the real MSBuild / xbuild engine for all types of projects. I would suggest using links instead of include.

Full background:

MonoDevelop has an old built-in build engine derived from the SharpDevelop 1.0 build engine, i.e. precedes the existence of MSBuild. We are moving on to MSBuild, but this has taken several steps and is not yet complete.

A few years ago, MonoDevelop switched its project file format to a Visual Studio-compatible subset of MSBuild. This was done by serializing / deserializing the known properties and elements of MSBuild in the internal model of the MD project, but doing the build using the old build mechanism. This meant that any MSBuild projects that used only the features available from the Visual Studio interface worked fine. However, it did not support the more advanced MSBuild features, available only by manually editing MSBuild XML.

MD later received experimental support for using the xbuild / MSBuild build engine, but at the time when xbuild was not mature and it did not have MSBuild goals for all types of projects. It remained experimental, and assembly code for new types of projects (MonoTouch, etc.) was written using the internal MD assembly mechanism.

Mono for Android needed to be supported in Visual Studio, so MSBuild objects had to be installed. Instead of writing and maintaining build code for the two build engines, we completed the integration of the xbuild engine and MonoDevelop MSBuild engine so that it can be used for Mono projects for Android. However, we could not enable the default xbuild build mechanism in MD, since many other types of projects did not yet have xbuild goals. Instead, we allowed projects to be added to force the xbuild mechanism for each type of project.

This is essentially the current state - the xbuild engine is used for Mono projects for Android and new types of projects, such as iPhone snap projects and PLP projects, and is recommended for new types of projects. But older types of projects, such as MonoTouch, MonoMac, ASP.NET, etc., have not yet been ported at the time of writing.

+9
source share

All Articles