Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for more properties #8

Merged
merged 2 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions DotNet.Bundle/BundleAppTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Dotnet.Bundle
Expand Down Expand Up @@ -45,6 +44,15 @@ public class BundleAppTask : Task
[Required]
public bool NSHighResolutionCapable { get; set; }

public bool NSRequiresAquaSystemAppearance {
get => NSRequiresAquaSystemAppearanceNullable.Value;
set => NSRequiresAquaSystemAppearanceNullable = value;
}

internal bool? NSRequiresAquaSystemAppearanceNullable { get; private set; }

public ITaskItem[] CFBundleURLTypes { get; set; }

public override bool Execute()
{
var builder = new StructureBuilder(this);
Expand Down
2 changes: 1 addition & 1 deletion DotNet.Bundle/DotNet.Bundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<NoPackageAnalysis>true</NoPackageAnalysis>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<Version>0.9.13</Version>
<Version>0.9.14</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
84 changes: 80 additions & 4 deletions DotNet.Bundle/PlistWriter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Xml;

using Microsoft.Build.Framework;

namespace Dotnet.Bundle
{
public class PlistWriter
{
private readonly BundleAppTask _task;
private readonly StructureBuilder _builder;
private readonly StructureBuilder _builder;

private static readonly string[] ArrayTypeProperties = { "CFBundleURLSchemes" };
private const char Separator = ';';

public PlistWriter(BundleAppTask task, StructureBuilder builder)
{
Expand Down Expand Up @@ -38,7 +44,8 @@ public void Write()
xmlWriter.WriteStartElement("plist");
xmlWriter.WriteAttributeString("version", "1.0");
xmlWriter.WriteStartElement("dict");


//This can be re-factored
WriteProperty(xmlWriter, nameof(_task.CFBundleName), _task.CFBundleName);
WriteProperty(xmlWriter, nameof(_task.CFBundleDisplayName), _task.CFBundleDisplayName);
WriteProperty(xmlWriter, nameof(_task.CFBundleIdentifier), _task.CFBundleIdentifier);
Expand All @@ -50,7 +57,18 @@ public void Write()
WriteProperty(xmlWriter, nameof(_task.CFBundleShortVersionString), _task.CFBundleShortVersionString);
WriteProperty(xmlWriter, nameof(_task.NSPrincipalClass), _task.NSPrincipalClass);
WriteProperty(xmlWriter, nameof(_task.NSHighResolutionCapable), _task.NSHighResolutionCapable);


if (_task.NSRequiresAquaSystemAppearanceNullable.HasValue)
{
WriteProperty(xmlWriter, nameof(_task.NSRequiresAquaSystemAppearance), _task.NSRequiresAquaSystemAppearanceNullable.Value);
}

if (_task.CFBundleURLTypes.Length != 0)
{
WriteProperty(xmlWriter, nameof(_task.CFBundleURLTypes), _task.CFBundleURLTypes);
}


xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}
Expand Down Expand Up @@ -86,6 +104,64 @@ private void WriteProperty(XmlWriter xmlWriter, string name, bool value)
}

xmlWriter.WriteEndElement();
}

private void WriteProperty(XmlWriter xmlWriter, string name, string[] values)
{
if (values.Length != 0)
{
xmlWriter.WriteStartElement("key");
xmlWriter.WriteString(name);
xmlWriter.WriteEndElement();

xmlWriter.WriteStartElement("array");
foreach (var value in values)
{
if (!string.IsNullOrEmpty(value))
{
xmlWriter.WriteStartElement("string");
xmlWriter.WriteString(value);
xmlWriter.WriteEndElement();
}
}

xmlWriter.WriteEndElement();
}
}


private void WriteProperty(XmlWriter xmlWriter, string name, ITaskItem[] values)
{
xmlWriter.WriteStartElement("key");
xmlWriter.WriteString(name);
xmlWriter.WriteEndElement();

xmlWriter.WriteStartElement("array");

foreach (var value in values)
{
xmlWriter.WriteStartElement("dict");
var metadataDictionary = value.CloneCustomMetadata();

foreach (DictionaryEntry entry in metadataDictionary)
{
var dictValue = entry.Value.ToString();
var dictKey = entry.Key.ToString();

if (dictValue.Contains(Separator.ToString()) || ArrayTypeProperties.Contains(dictKey)) //array
{
WriteProperty(xmlWriter, dictKey, dictValue.Split(Separator));
}
else
{
WriteProperty(xmlWriter, dictKey, dictValue);
}
}

xmlWriter.WriteEndElement(); //End dict
}

xmlWriter.WriteEndElement(); //End outside array
}
}
}
2 changes: 2 additions & 0 deletions DotNet.Bundle/build/DotNet.Bundle.targets
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
CFBundleShortVersionString="$(CFBundleShortVersionString)"
NSPrincipalClass="$(NSPrincipalClass)"
NSHighResolutionCapable="$(NSHighResolutionCapable)"
NSRequiresAquaSystemAppearance="$(NSRequiresAquaSystemAppearance)"
CFBundleURLTypes="@(CFBundleURLTypes)"
/>

</Target>
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Command-line interface tools for bundling .NET Core projects into MacOS applicat

### Installation

Install MSBuild task via NuGet package: ```Dotnet.Bundle```
Install MSBuild task via NuGet package: `Dotnet.Bundle`

[![NuGet](https://img.shields.io/nuget/v/Dotnet.Bundle.svg)](https://www.nuget.org/packages/Dotnet.Bundle/)

Expand Down Expand Up @@ -34,7 +34,22 @@ Define properties to override default bundle values
<CFBundleIconFile>AppName.icns</CFBundleIconFile> <!-- Will be copied from output directory -->
<NSPrincipalClass>NSApplication</NSPrincipalClass>
<NSHighResolutionCapable>true</NSHighResolutionCapable>

<!-- Optional -->
<NSRequiresAquaSystemAppearance>true</NSRequiresAquaSystemAppearance>
</PropertyGroup>

<ItemGroup>
<!-- Optional URLTypes.Check TestBundle.csproj for a working example. -->
<CFBundleURLTypes Include="dummy"> <!-- The name of this file is irrelevant, it's a MSBuild requirement.-->
<CFBundleURLName>TestApp URL</CFBundleURLName>
<CFBundleURLSchemes>testappurl;testappurl://</CFBundleURLSchemes> <!-- Note the ";" separator-->
</CFBundleURLTypes>
<CFBundleURLTypes Include="dummy">
<CFBundleURLName>TestApp URL2</CFBundleURLName>
<CFBundleURLSchemes>test://</CFBundleURLSchemes>
</CFBundleURLTypes>
</ItemGroup>
```

More info: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
More info: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
53 changes: 53 additions & 0 deletions TestBundle/TestBundle.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>..\Build\$(Configuration)\</OutputPath>
<TargetFramework>net5.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifiers>osx-x64</RuntimeIdentifiers>
<RestoreSources>$(RestoreSources);..\\Dotnet.Bundle\\bin\\$(Configuration)\\</RestoreSources>
<DotnetBundleTestVersion>9.9.999952</DotnetBundleTestVersion>
<CustomCommands>
<CustomCommands>
<Command>
<type>BeforeBuild</type>
<command>dotnet pack ..\\Dotnet.Bundle\\ -p:Configuration=$(Configuration) -p:PackageVersion=$(DotnetBundleTestVersion)</command>
</Command>
<Command>
<type>BeforeBuild</type>
<command>dotnet restore</command>
</Command>
<Command>
<type>AfterBuild</type>
<command>dotnet msbuild -t:BundleApp -p:RuntimeIdentifier=osx-x64 -p:Configuration=$(Configuration)</command>
</Command>
</CustomCommands>
</CustomCommands>
</PropertyGroup>

<!-- Defines Info.plist -->
<PropertyGroup>
<CFBundleName>TestBundle</CFBundleName>
<CFBundleDisplayName>TestBundle</CFBundleDisplayName>
<CFBundleShortVersionString>TestBundle</CFBundleShortVersionString>
<CFBundleIconFile>IconTest.icns</CFBundleIconFile>
<NSPrincipalClass>NSApplication</NSPrincipalClass>
<CFBundlePackageType>AAPL</CFBundlePackageType>
<CFBundleSignature>4242</CFBundleSignature>
<NSRequiresAquaSystemAppearance>false</NSRequiresAquaSystemAppearance>
</PropertyGroup>
<ItemGroup>
<CFBundleURLTypes Include="dummy">
<CFBundleURLName>TestApp URL</CFBundleURLName>
<CFBundleURLSchemes>testappurl;testappurl://</CFBundleURLSchemes>
</CFBundleURLTypes>
<CFBundleURLTypes Include="dummy">
<CFBundleURLName>TestApp URL2</CFBundleURLName>
<CFBundleURLSchemes>test://</CFBundleURLSchemes>
</CFBundleURLTypes>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dotnet.Bundle" Version="$(DotnetBundleTestVersion)" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions dotnet-bundle.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet.Bundle", "DotNet.Bundle\DotNet.Bundle.csproj", "{CB54F0FD-7C7E-4347-BE12-5880C6C86ABF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestBundle", "TestBundle\TestBundle.csproj", "{967D02F2-36B8-4A22-A024-53F81FEA7C1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +15,9 @@ Global
{CB54F0FD-7C7E-4347-BE12-5880C6C86ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB54F0FD-7C7E-4347-BE12-5880C6C86ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB54F0FD-7C7E-4347-BE12-5880C6C86ABF}.Release|Any CPU.Build.0 = Release|Any CPU
{967D02F2-36B8-4A22-A024-53F81FEA7C1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{967D02F2-36B8-4A22-A024-53F81FEA7C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{967D02F2-36B8-4A22-A024-53F81FEA7C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{967D02F2-36B8-4A22-A024-53F81FEA7C1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal