Skip to content

Commit ba46f03

Browse files
committed
Add support for exporting .slnx solution files
1 parent fde6781 commit ba46f03

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

dnSpy/dnSpy.Decompiler/MSBuild/SdkProjectWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public override void Write() {
6060
var settings = new XmlWriterSettings {
6161
Encoding = Encoding.UTF8,
6262
Indent = true,
63+
OmitXmlDeclaration = true
6364
};
6465
using (var writer = XmlWriter.Create(project.Filename, settings)) {
6566
project.Platform = GetPlatformString();

dnSpy/dnSpy.Decompiler/MSBuild/SolutionWriter.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ You should have received a copy of the GNU General Public License
2222
using System.IO;
2323
using System.Linq;
2424
using System.Text;
25+
using System.Xml;
2526
using dnlib.PE;
2627

2728
namespace dnSpy.Decompiler.MSBuild {
@@ -62,6 +63,13 @@ public SolutionWriter(ProjectVersion projectVersion, IList<Project> projects, st
6263
}
6364

6465
public void Write() {
66+
if (Path.GetExtension(filename) == ".slnx")
67+
WriteXmlSolution();
68+
else
69+
WriteVisualStudioSolution();
70+
}
71+
72+
private void WriteVisualStudioSolution() {
6573
Directory.CreateDirectory(Path.GetDirectoryName(filename)!);
6674
using (var writer = new StreamWriter(filename, false, Encoding.UTF8)) {
6775
const string crlf = "\r\n"; // Make sure it's always CRLF
@@ -172,5 +180,45 @@ public void Write() {
172180
writer.Write("EndGlobal" + crlf);
173181
}
174182
}
183+
184+
private void WriteXmlSolution() {
185+
Directory.CreateDirectory(Path.GetDirectoryName(filename)!);
186+
187+
var settings = new XmlWriterSettings {
188+
Encoding = Encoding.UTF8,
189+
Indent = true,
190+
OmitXmlDeclaration = true
191+
};
192+
193+
using (var writer = XmlWriter.Create(filename, settings)) {
194+
writer.WriteStartElement("Solution");
195+
196+
if (platforms.Count != 1 || platforms[0] != "Any CPU") {
197+
writer.WriteStartElement("Configurations");
198+
199+
foreach (var p in platforms) {
200+
if (p == "Mixed Platforms")
201+
continue;
202+
writer.WriteStartElement("Platform");
203+
writer.WriteAttributeString("Name", p);
204+
writer.WriteEndElement();
205+
}
206+
207+
writer.WriteEndElement();
208+
}
209+
210+
foreach (var p in projects) {
211+
writer.WriteStartElement("Project");
212+
213+
var relativePath = Path.Combine(Path.GetFileName(Path.GetDirectoryName(p.Filename)!),
214+
Path.GetFileName(p.Filename));
215+
216+
writer.WriteAttributeString("Path", relativePath);
217+
writer.WriteEndElement();
218+
}
219+
220+
writer.WriteEndElement();
221+
}
222+
}
175223
}
176224
}

0 commit comments

Comments
 (0)