4 using System.Collections.Generic;
7 using System.Text.RegularExpressions;
17 private static readonly Regex PlatformRegex =
new Regex(
@"'\$\(Configuration\)\|\$\(Platform\)' == '(?<Configuration>.*)\|(?<Platform>.*)'");
23 public static void Execute(
string buildRootPath)
25 UpdateProjectFile(Path.Combine(buildRootPath,
@"GeneratedProjects\UWP\Assembly-CSharp\Assembly-CSharp.csproj"));
26 UpdateProjectFile(Path.Combine(buildRootPath,
@"GeneratedProjects\UWP\Assembly-CSharp-firstpass\Assembly-CSharp-firstpass.csproj"));
34 private static void UpdateProjectFile(
string filename)
36 if (!File.Exists(filename))
38 UnityEngine.Debug.LogWarningFormat(
"Unable to find file \"{0}\", double check that the build succeeded and that the C# Projects are set to be generated.", filename);
42 var projectDocument =
new XmlDocument();
43 projectDocument.Load(filename);
45 if (projectDocument.DocumentElement == null)
47 UnityEngine.Debug.LogWarningFormat(
"Unable to load file \"{0}\", double check that the build succeeded and that the C# Projects are set to be generated.", filename);
51 if (projectDocument.DocumentElement.Name !=
"Project")
53 UnityEngine.Debug.LogWarningFormat(
"The loaded project \"{0}\", does not appear to be a MSBuild Project file.", filename);
57 foreach (XmlNode node
in projectDocument.DocumentElement.ChildNodes)
60 if (node.Name !=
"PropertyGroup" || node.Attributes == null)
65 if (node.Attributes.Count == 0 && node[
"Configuration"] != null && node[
"Platform"] != null)
68 node[
"Configuration"].InnerText =
"Release";
69 node[
"Platform"].InnerText =
"x86";
71 else if (node.Attributes[
"Condition"] != null)
74 Match match = PlatformRegex.Match(node.Attributes[
"Condition"].InnerText);
78 UpdateDefineConstants(node[
"DefineConstants"], match.Groups[
"Configuration"].Value, match.Groups[
"Platform"].Value);
83 WriteXmlDocumentToFile(projectDocument, filename);
86 private static void UpdateDefineConstants(XmlNode defineConstants,
string configuration,
string platform)
88 if (defineConstants == null)
93 IEnumerable<string> symbols = defineConstants.InnerText.Split(
';').Except(
new[]
99 }).Union(
new[] { configuration.ToUpperInvariant() });
101 defineConstants.InnerText =
string.Join(
";", symbols.ToArray());
105 private static void WriteXmlDocumentToFile(XmlNode document,
string fullPath)
107 FileStream fileStream = null;
110 fileStream = File.Open(fullPath, FileMode.Create);
112 var settings =
new XmlWriterSettings
118 using (XmlWriter writer = XmlWriter.Create(fileStream, settings))
121 document.WriteTo(writer);
126 if (fileStream != null)
128 fileStream.Dispose();
This class is designed to post process the UWP Assembly-CSharp projects to ensure that the defaults a...
static void Execute(string buildRootPath)
Executes the Post Processes on the C# Projects generated as part of the UWP build.