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

[xharness] Add support for adding PropertyGroups for unknown platform/configuration values in a csproj. Fixes xamarin/maccore@2277. #9347

Merged
merged 1 commit into from
Aug 12, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,25 @@ public static void AddAdditionalDefines (this XmlDocument csproj, string value,
return;
}

throw new Exception ("Could not find where to add a new DefineConstants node");
// Create a new PropertyGroup with the desired condition, and add it just after the last PropertyGroup in the csproj.
var projectNode = csproj.SelectSingleNode ("//*[local-name() = 'Project']");
var lastPropertyGroup = csproj.SelectNodes ("//*[local-name() = 'PropertyGroup']").Cast<XmlNode> ().Last ();
var newPropertyGroup = csproj.CreateElement ("PropertyGroup", csproj.GetNamespace ());
var conditionAttribute = csproj.CreateAttribute ("Condition");
var condition = "";
if (!string.IsNullOrEmpty (platform))
condition = $"'$(Platform)' == '{platform}'";
if (!string.IsNullOrEmpty (configuration)) {
if (!string.IsNullOrEmpty (condition))
condition += " And ";
condition += $"'$(Configuration)' == '{configuration}'";
}
conditionAttribute.Value = condition;
newPropertyGroup.Attributes.Append (conditionAttribute);
var defineConstantsElement = csproj.CreateElement ("DefineConstants", csproj.GetNamespace ());
defineConstantsElement.InnerText = "$(DefineConstants);" + value;
newPropertyGroup.AppendChild (defineConstantsElement);
projectNode.InsertAfter (newPropertyGroup, lastPropertyGroup);
}

public static void AddTopLevelProperty (this XmlDocument csproj, string property, string value)
Expand Down