Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Turns out this is in fact quite possible with MSBuild. The key points, assuming you're starting out with a C# project created for Windows .NET that you want to also compile for iOS are as follows. <strong>Note: this does not work with MonoDevelop. It only works with Visual Studio.</strong> This is because MonoDevelop does not currently use a full-fledged MSBuild compatible build system for MonoTouch.</p> <ol> <li>Create a new solution and project platform for iOS, named iOS. This is used to compile the project for MonoTouch. You can name this anything you want, but use the name consistently in what follows.</li> <li><p>For the iOS platform, set NoStdLib to true to avoid automatically referencing mscorlib.dll. Also set the path to a directory that contains local copies of the MonoTouch dll's, copied from your MonoTouch installation on a Mac:</p> <pre><code>&lt;PropertyGroup Condition="'$(Platform'=='iOS'"&gt; &lt;NoStdLib&gt;true&lt;/NoStdLib&gt; &lt;iOSLibs&gt;c:\MonoTouch\&lt;/iOSLibs&gt; &lt;/PropertyGroup&gt;` </code></pre></li> <li><p>Add references to local copies of all referenced MonoTouch assemblies from the folder:</p> <pre><code>&lt;ItemGroup Condition="'$(Platform'=='iOS'"&gt; &lt;Reference Include="mscorlib"&gt; &lt;HintPath&gt;$(iOSLibs)\mscorlib.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;Reference Include="System"&gt; &lt;HintPath&gt;$(iOSLibs)\System.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;Reference Include="System.Core"&gt; &lt;HintPath&gt;$(iOSLibs)\System.Core.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;Reference Include="System.Xml"&gt; &lt;HintPath&gt;$(iOSLibs)\System.Xml.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;Reference Include="System.Xml.Linq"&gt; &lt;HintPath&gt;$(iOSLibs)\System.Xml.Linq.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;Reference Include="monotouch"&gt; &lt;HintPath&gt;$(iOSLibs)\monotouch.dll&lt;/HintPath&gt; &lt;/Reference&gt; &lt;/ItemGroup&gt; </code></pre></li> <li><p>Visual Studio automatically adds an ItemGroup referencing all the .NET assemblies. Since we've instructed Visual Studio/MSBuild to get these from the iOSLibs folder when building for iOS, we should conditionally disable the default assemblies. This stops VS from complaining about duplicate assembly references. Change the first line of the <code>ItemGroup</code> and add the condition as follows. (Note: the list of assemblies will differ depending on what your project currently references.)</p> <pre><code>&lt;ItemGroup Condition=" '$(Platform)' != 'iOS' "&gt; &lt;Reference Include="System" /&gt; &lt;Reference Include="System.Core" /&gt; &lt;Reference Include="System.Drawing" /&gt; &lt;Reference Include="System.Windows.Forms" /&gt; &lt;Reference Include="System.Xml.Linq" /&gt; &lt;Reference Include="System.Data.DataSetExtensions" /&gt; &lt;Reference Include="Microsoft.CSharp" /&gt; &lt;Reference Include="System.Data" /&gt; &lt;Reference Include="System.Xml" /&gt; &lt;/ItemGroup&gt; </code></pre></li> </ol> <p>Now you're ready to go. Once you have done this for all the projects in your solution, you can select iOS from the Solution drop down and build MonoTouch binary-compatible assemblies like magic, <em>without</em> the use of Portable Class Libraries! (This does not mean that PCLs are not useful, they certainly are, but the technique shown here is much more generally applicable.)</p> <p>A more detailed knowledge of MSBuild and its considerable power will help you simplify even more, e.g.:</p> <ol> <li>Moving much of the above into a common MSBuild file that you can reference from all your project files to eliminate duplication.</li> <li>Defining compiler constants using <code>&lt;DefineConstants&gt;...&lt;/DefineConstants&gt;</code> to allow your code to do things differently based on the current solution and configuration.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload