-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,7 @@ | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<!-- <Import Project="EmbedReferences.targets" /> --> | ||
<Import Project="UpdatePList.targets" /> | ||
|
||
<UsingTask TaskName="_ParseVersion" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> | ||
<ParameterGroup> | ||
<Version ParameterType="System.String" Required="true" /> | ||
<AssemblyVersion ParameterType="System.String" Output="true" /> | ||
<AssemblyFileVersion ParameterType="System.String" Output="true" /> | ||
<AssemblyInformationalVersion ParameterType="System.String" Output="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Using Namespace="System"/> | ||
<Using Namespace="System.IO"/> | ||
<Using Namespace="System.Text.RegularExpressions"/> | ||
<Code Type="Fragment" Language="cs"><![CDATA[ | ||
var regex = new Regex(@"(?<ver>(?<maj>\d+)[.](?<min>\d+)([.](?<build>\d+)([.](?<rev>\d+))?)?)([-](?<info>.+))?"); | ||
if (string.IsNullOrEmpty(AssemblyVersion)) AssemblyVersion = regex.Replace(Version, "${ver}"); | ||
if (string.IsNullOrEmpty(AssemblyFileVersion)) AssemblyFileVersion = AssemblyFileVersion ?? regex.Replace(Version, "${ver}"); | ||
if (string.IsNullOrEmpty(AssemblyInformationalVersion)) AssemblyInformationalVersion = Version; | ||
]]></Code> | ||
</Task> | ||
</UsingTask> | ||
|
||
<Target Name="_ParseAssemblyVersion" BeforeTargets="BeforeBuild"> | ||
|
||
<_ParseVersion Version="$(Version)"> | ||
<Output TaskParameter="AssemblyVersion" PropertyName="AssemblyVersion"/> | ||
<Output TaskParameter="AssemblyFileVersion" PropertyName="AssemblyFileVersion"/> | ||
<Output TaskParameter="AssemblyInformationalVersion" PropertyName="AssemblyInformationalVersion"/> | ||
</_ParseVersion> | ||
</Target> | ||
<!-- <Import Project="EmbedReferences.targets" /> --> | ||
|
||
<Target Name="_WriteVersion" BeforeTargets="CoreCompile" Condition="$(GenerateAssemblyVersion) == 'True'" | ||
Inputs="$(MSBuildAllProjects);@(Compile);@(_CoreCompileResourceInputs);$(ApplicationIcon);$(AssemblyOriginatorKeyFile);@(ReferencePathWithRefAssemblies);@(CompiledLicenseFile);@(LinkResource);@(EmbeddedDocumentation);$(Win32Resource);$(Win32Manifest);@(CustomAdditionalCompileInputs);$(ResolvedCodeAnalysisRuleSet);@(AdditionalFiles);@(EmbeddedFiles)" | ||
Outputs="$(IntermediateOutputPath)VersionInfo.cs"> | ||
|
||
<ItemGroup> | ||
<VersionInfo Include="[assembly: System.Reflection.AssemblyVersion("$(AssemblyVersion)")]" /> | ||
<VersionInfo Include="[assembly: System.Reflection.AssemblyFileVersion("$(AssemblyFileVersion)")]" /> | ||
<VersionInfo Include="[assembly: System.Reflection.AssemblyInformationalVersion("$(AssemblyInformationalVersion)")]" /> | ||
</ItemGroup> | ||
<MakeDir Directories="$(IntermediateOutputPath)" /> | ||
<WriteLinesToFile File="$(IntermediateOutputPath)VersionInfo.cs" Overwrite="True" Lines="@(VersionInfo)" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
|
||
<UsingTask TaskName="UpdatePListEntries" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> | ||
<ParameterGroup> | ||
<TargetFile ParameterType="System.String" Required="true" /> | ||
<Entries ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | ||
<IconFile ParameterType="System.String" Output="true" /> | ||
</ParameterGroup> | ||
<Task> | ||
<Reference Include="netstandard" /> | ||
<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 UpdatePListEntries : Task | ||
{ | ||
[Required] | ||
public string TargetFile { get; set; } | ||
[Required] | ||
public Microsoft.Build.Framework.ITaskItem[] Entries { 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(TargetFile); | ||
dict = xml.SelectSingleNode("plist/dict") as XmlElement; | ||
foreach (var entry in Entries) | ||
{ | ||
if (!bool.TryParse(entry.GetMetadata("Force"), out var force)) | ||
force = false; | ||
AddStringProperty(entry.ItemSpec, entry.GetMetadata("Value"), force); | ||
} | ||
IconFile = GetStringProperty("CFBundleIconFile"); | ||
using (var sw = new NullSubsetXmlTextWriter(TargetFile, Encoding.UTF8)) | ||
xml.Save(sw); | ||
return true; | ||
} | ||
} | ||
]]></Code> | ||
</Task> | ||
</UsingTask> | ||
|
||
|
||
</Project> |