[xharness] Add support for getting the default AssemblyName for projects. (#9369)

In .NET projects there's a default value for most properties, which means that
there won't necessarily be an AssemblyName property in a csproj. We need to know the
AssemblyName, so calculate it from the csproj filename (which is how .NET does it).

This turned out slighly complicated, because we're pass an XmlDocument around,
and the XmlDocument doesn't know the file from where it was loaded, so we need
to keep that information separately.
This commit is contained in:
Rolf Bjarne Kvinge 2020-08-14 10:32:23 +02:00 коммит произвёл GitHub
Родитель 33ecd581ac
Коммит b28997fa8a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -1,8 +1,17 @@
using System.IO;
using System.Runtime.CompilerServices;
using System.Xml;
namespace Microsoft.DotNet.XHarness.iOS.Shared.Utilities {
public static class PListExtensions {
static ConditionalWeakTable<XmlDocument, string> doc_to_filename = new ConditionalWeakTable<XmlDocument, string> ();
public static string GetFilename (this XmlDocument doc)
{
doc_to_filename.TryGetValue (doc, out var rv);
return rv;
}
public static void LoadWithoutNetworkAccess (this XmlDocument doc, string filename)
{
using (var fs = new FileStream (filename, FileMode.Open, FileAccess.Read)) {
@ -14,6 +23,7 @@ namespace Microsoft.DotNet.XHarness.iOS.Shared.Utilities {
doc.Load (reader);
}
}
doc_to_filename.Add (doc, filename);
}
public static void LoadXmlWithoutNetworkAccess (this XmlDocument doc, string xml)

Просмотреть файл

@ -246,7 +246,10 @@ namespace Microsoft.DotNet.XHarness.iOS.Shared.Utilities {
public static string GetAssemblyName (this XmlDocument csproj)
{
return csproj.SelectSingleNode ("/*/*/*[local-name() = 'AssemblyName']").InnerText;
var assemblyNameNode = csproj.SelectSingleNode ("/*/*/*[local-name() = 'AssemblyName']");
if (assemblyNameNode != null)
return assemblyNameNode.InnerText;
return Path.GetFileNameWithoutExtension (csproj.GetFilename ());
}
public static void SetPlatformAssembly (this XmlDocument csproj, string value)