Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch to get Eto.Forms 2.4.1 building/running with dotnet build
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
<ItemGroup>
<AvailableItemName Include="BundleResource" />
</ItemGroup>
<PropertyGroup>
<IsMac Condition="'$(OS)' == 'Unix' and $([System.IO.File]::Exists('/usr/lib/libc.dylib'))">True</IsMac>
<MacBundleName Condition="'$(MacBundleName)'==''">$(MSBuildProjectName)</MacBundleName>
<InputAppPath Condition="'$(InputAppPath)'==''">$(MSBuildProjectDirectory)\Mac\</InputAppPath>
<OutputAppPath Condition="'$(OutputAppPath)'==''">$(TargetDir)\$(MacBundleName).app</OutputAppPath>
<MacSetDefaultRunConfiguration Condition="'$(MacSetDefaultTarget)' == ''">True</MacSetDefaultRunConfiguration>
<MacBuildBundle Condition="$(MacBuildBundle) == '' and $(ProjectTypeGuids) == ''">True</MacBuildBundle>
</PropertyGroup>
<Target Name="_BuildAppBundle" AfterTargets="AfterBuild" Condition="$(MacBuildBundle) == 'True'">
<PropertyGroup>
<OutputContents>$(OutputAppPath)\Contents</OutputContents>
<OutputMonoBundlePath>$(OutputContents)\MonoBundle</OutputMonoBundlePath>
<OutputResourcesPath>$(OutputContents)\Resources</OutputResourcesPath>
<LauncherFile>$([System.IO.Path]::GetFileNameWithoutExtension('$(TargetFileName)'))</LauncherFile>
<LauncherFileWithPath>$(OutputContents)\MacOS\$(LauncherFile)</LauncherFileWithPath>
<HasXamMac>@(ReferenceCopyLocalPaths->AnyHaveMetadataValue('Filename', 'Eto.XamMac2'))</HasXamMac>
<Has32Bit>@(ReferenceCopyLocalPaths->AnyHaveMetadataValue('Filename', 'Eto.Mac'))</Has32Bit>
<Has64Bit>@(ReferenceCopyLocalPaths->AnyHaveMetadataValue('Filename', 'Eto.Mac64'))</Has64Bit>
<Has64Bit Condition="$(Has64Bit) != 'True'">$(HasXamMac)</Has64Bit>
<MacIncludeSymbols Condition="'$(MacIncludeSymbols)' == ''">true</MacIncludeSymbols>
<MacArch Condition="'$(MacArch)'=='' AND $(Has64Bit)=='true'">x86_64</MacArch>
<MacArch Condition="'$(MacArch)'==''">i386</MacArch>
<!-- *** Adjust as needed *** -->
<ReferenceFiles>$(USERPROFILE)/.nuget/packages/eto.platform.mac64/2.4.1/build</ReferenceFiles>
<OutputPListFile>$(OutputContents)\Info.plist</OutputPListFile>
<InputPListFile Condition="'@(None->WithMetadataValue('Identity', 'Info.plist')->Distinct())' != ''">$(MSBuildProjectDirectory)\@(None->WithMetadataValue('Identity', 'Info.plist')->Distinct())</InputPListFile>
<InputPListFile Condition="'$(InputPListFile)' == ''">$(ReferenceFiles)\Info.plist</InputPListFile>
<LauncherExecutable Condition="'$(LauncherExecutable)' == '' AND $(MacArch)=='x86_64'">$(ReferenceFiles)\Launcher64</LauncherExecutable>
<LauncherExecutable Condition="'$(LauncherExecutable)' == '' AND $(MacArch)=='i386'">$(ReferenceFiles)\Launcher32</LauncherExecutable>
<XamarinMacAssembly Condition="$(XamarinMacAssembly) == '' AND Exists('$(ReferenceFiles)\Xamarin.Mac.dll')">$(ReferenceFiles)\Xamarin.Mac.dll</XamarinMacAssembly>
<XamarinMacAssembly Condition="$(XamarinMacAssembly) == '' AND Exists('\Library\Frameworks\Xamarin.Mac.framework\Versions\Current\lib\x86_64\full\Xamarin.Mac.dll')">\Library\Frameworks\Xamarin.Mac.framework\Versions\Current\lib\x86_64\full\Xamarin.Mac.dll</XamarinMacAssembly>
</PropertyGroup>
<Message Text="Creating $(MacBundleName).app in target directory" Importance="high" />
<Warning Text=" Warning: Both Eto.Mac and Eto.Mac64 platforms references detected. Building 64-bit only. " Condition="$(Has32Bit)=='true' and $(Has64Bit)=='true'" />
<!-- Delete existing stuff, we're going to rebuild them -->
<RemoveDir Directories="$(OutputMonoBundlePath)" />
<Delete Files="$(OutputPListFile)" />
<!-- Copy icon/launcher/etc -->
<Copy SourceFiles="$(InputAppPath)\**\*.*" DestinationFolder="$(OutputContents)" SkipUnchangedFiles="true" Condition="Exists('$(InputAppPath)')" />
<Copy SourceFiles="$(LauncherExecutable)" DestinationFiles="$(LauncherFileWithPath)" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(InputPListFile)" DestinationFiles="$(OutputPListFile)" Condition="!Exists('$(OutputPListFile)')" />
<Copy SourceFiles="$(XamarinMacAssembly)" DestinationFolder="$(OutputMonoBundlePath)" SkipUnchangedFiles="true" Condition="$(HasXamMac) == 'True'" />
<FindUnderPath
Files="@(FileWrites)"
Path="$(TargetDir)">
<Output TaskParameter="InPath" ItemName="ExecutableFiles" />
</FindUnderPath>
<!-- Copy ouput files, except for non-mac Eto platforms -->
<ItemGroup>
<!--ExecutableFiles Include="$(TargetDir)\**" Exclude="$(OutputAppPath)\**\*" /-->
<ExecutableFiles Include="@(MacExecutableFiles->'$(TargetDir)%(Identity)')" />
<ExecutableFiles Include="@(None)" Condition="%(None.CopyToOutputDirectory) != ''" />
<ExecutableFiles Include="@(ReferenceCopyLocalPaths)" Condition="
!(%(Filename) == 'Eto' and %(Extension) == '.xml')
and %(Filename) != 'Eto.Direct2D'
and %(Filename) != 'Eto.Gtk2'
and %(Filename) != 'Eto.Gtk3'
and %(Filename) != 'Eto.Wpf'
and %(Filename) != 'Eto.WinForms'
and %(Filename) != 'Eto.iOS'
and %(Filename) != 'Eto.WinRT'
and %(Filename) != 'Eto.Android'
and %(Filename) != 'Eto.XamMac'
and (
$(MacIncludeSymbols) == 'True'
or (
%(Extension) != '.pdb'
and %(Extension) != '.mdb'
)
)
and (($(HasXamMac) != 'True' and $(Has32Bit) == 'True') or %(Filename) != 'Eto.Mac')
and (($(HasXamMac) != 'True' and $(Has64Bit) == 'True') or %(Filename) != 'Eto.Mac64')
and ($(HasXamMac) == 'True' or %(Filename) != 'Eto.XamMac2')
" />
<ResourceFiles Include="@(BundleResource)" />
<ResourceFiles Include="@(Content)" />
</ItemGroup>
<!-- copy executable files -->
<Copy SourceFiles="@(ExecutableFiles)" DestinationFolder="$(OutputMonoBundlePath)\%(RecursiveDir)" />
<Copy SourceFiles="@(ResourceFiles)" DestinationFolder="$(OutputResourcesPath)\%(RecursiveDir)" SkipUnchangedFiles="true" />
<!--
Add any missing keys to the PListFile
-->
<Warning Text="A reference to the NuGet package RoslynCodeTaskFactory is required in this project"
Condition=" '$(RoslynCodeTaskFactory)' == '' " />
<_UpdatePList
PListFile="$(OutputPListFile)"
TargetFileName="$(TargetFileName)"
MacBundleName="$(MacBundleName)"
LauncherFile="$(LauncherFile)">
<Output PropertyName="IconFile" TaskParameter="IconFile" />
</_UpdatePList>
<Message Text=" MacArch: $(MacArch)" Importance="low" />
<Message Text=" Icon: $(IconFile)" Importance="low" />
<Message Text=" Info: $(InputPListFile)" Importance="low" />
<!-- Copy default icon if it doesn't exist -->
<Copy SourceFiles="$(ReferenceFiles)\Icon.icns" DestinationFiles="$(OutputResourcesPath)\$(IconFile)" Condition="!Exists('$(OutputResourcesPath)\$(IconFile)')" />
<!-- Set executable bit on launcher if on *nix -->
<Exec Command="chmod +x &quot;$(LauncherFileWithPath)&quot;" Condition="'$(OS)'=='Unix'" />
</Target>
<UsingTask TaskName="_UpdatePList" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)"
Condition=" '$(RoslynCodeTaskFactory)' != '' ">
<Task>
<Reference Include="System.Xml" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Xml" />
<Code Type="Class" Language="cs"><![CDATA[
using System;
using System.IO;
using System.Xml;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class _UpdatePList : Task
{
[Required]
public string PListFile { get; set; }
[Required]
public string TargetFileName { get; set; }
[Required]
public string MacBundleName { get; set; }
[Required]
public string LauncherFile { get; set; }
[Output]
public string IconFile { get; set; }
XmlDocument xml;
XmlNode dict;
class NullSubsetXmlTextWriter : XmlTextWriter
{
XmlWriterSettings _settings;
public NullSubsetXmlTextWriter(string inputFileName, Encoding encoding)
: base(inputFileName, encoding)
{
Formatting = Formatting.Indented;
IndentChar = ' ';
Indentation = 2;
_settings = new XmlWriterSettings();
_settings.Encoding = Encoding.UTF8;
_settings.Indent = true;
_settings.IndentChars = " ";
_settings.NewLineChars = "\n";
_settings.NewLineHandling = NewLineHandling.Entitize;
}
public override XmlWriterSettings Settings { get { return _settings; } }
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
// fix issue writing doctype
if (subset == string.Empty)
subset = null;
base.WriteDocType(name, pubid, sysid, subset);
}
}
string GetStringProperty(string name)
{
var location = dict.SelectSingleNode("key[.='" + name + "']/following-sibling::string[1]");
return location.InnerText;
}
void AddStringProperty(string name, string value, bool force = false)
{
XmlNode node;
var exists = dict.SelectSingleNode("key[text()='" + name + "']") != null;
if (exists && !force)
return;
dict.AppendChild(node = xml.CreateNode(XmlNodeType.Element, "key", null));
node.InnerText = name;
dict.AppendChild(node = xml.CreateNode(XmlNodeType.Element, "string", null));
node.InnerText = value;
}
public override bool Execute()
{
xml = new XmlDocument();
xml.Load(PListFile);
dict = xml.SelectSingleNode("plist/dict") as XmlElement;
AddStringProperty("CFBundleIconFile", "Icon.icns");
IconFile = GetStringProperty("CFBundleIconFile");
AddStringProperty("CFBundleInfoDictionaryVersion", "6.0");
AddStringProperty("CFBundlePackageType", "APPL");
AddStringProperty("CFBundleSignature", "????");
AddStringProperty("NSPrincipalClass", "NSApplication");
AddStringProperty("CFBundleName", MacBundleName);
AddStringProperty("CFBundleExecutable", LauncherFile, true);
AddStringProperty("LSMinimumSystemVersion", "10.7");
using (var sw = new NullSubsetXmlTextWriter(PListFile, Encoding.UTF8))
xml.Save(sw);
return true;
}
}
]]></Code>
</Task>
</UsingTask>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment