Browse Source

write EmbeddedResource for non .resx file

pull/2186/head
文煌 5 years ago committed by Siegfried Pammer
parent
commit
bc888117e9
  1. 36
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

36
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

@ -72,11 +72,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -72,11 +72,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
using (XmlTextWriter xmlWriter = new XmlTextWriter(target))
{
xmlWriter.Formatting = Formatting.Indented;
Write(xmlWriter, project, module);
Write(xmlWriter, project, files, module);
}
}
static void Write(XmlTextWriter xml, IProjectInfoProvider project, PEFile module)
static void Write(XmlTextWriter xml, IProjectInfoProvider project, IEnumerable<(string itemType, string fileName)> files, PEFile module)
{
xml.WriteStartElement("Project");
@ -85,6 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -85,6 +85,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
PlaceIntoTag("PropertyGroup", xml, () => WriteAssemblyInfo(xml, module, project, projectType));
PlaceIntoTag("PropertyGroup", xml, () => WriteProjectInfo(xml, project));
PlaceIntoTag("ItemGroup", xml, () => WriteResources(xml, module, files, project));
PlaceIntoTag("ItemGroup", xml, () => WriteReferences(xml, module, project));
xml.WriteEndElement();
@ -179,6 +180,37 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -179,6 +180,37 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
}
}
static void WriteResources(XmlTextWriter xml, PEFile module, IEnumerable<(string itemType, string fileName)> files, IProjectInfoProvider project)
{
// remove phase
foreach (var file in files.Where(t => t.itemType == "EmbeddedResource"))
{
string buildAction = Path.GetExtension(file.fileName).ToUpperInvariant() switch
{
".CS" => "Compile",
".RESX" => "EmbeddedResource",
_ => "None"
};
if (buildAction == "EmbeddedResource")
continue;
xml.WriteStartElement(buildAction);
xml.WriteAttributeString("Remove", file.fileName);
xml.WriteEndElement();
}
// include phase
foreach (var file in files.Where(t => t.itemType == "EmbeddedResource"))
{
if (Path.GetExtension(file.fileName) == ".resx")
continue;
xml.WriteStartElement("EmbeddedResource");
xml.WriteAttributeString("Include", file.fileName);
xml.WriteEndElement();
}
}
static void WriteReferences(XmlTextWriter xml, PEFile module, IProjectInfoProvider project)
{
foreach (var reference in module.AssemblyReferences.Where(r => !ImplicitReferences.Contains(r.Name)))

Loading…
Cancel
Save