Skip to content

Commit b039d9c

Browse files
authored
Respect <link> elements when importing XNA content projects. (MonoGame#8684)
Fixes MonoGame#8683 ### Description of Change Fixes importing contentproj files that reference files outside the project directory. Visual Studio puts a `<Link>` in a `<Content>`, `<Compile>` or `<None>` element to show the desired position in the structure, which MGCB was not respecting.
1 parent 86401b2 commit b039d9c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Tools/MonoGame.Content.Builder.Editor/Common/PipelineProjectParser.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,23 @@ public void ImportProject(string projectFilePath)
448448
}
449449
else if (buildAction.Equals("Content") || buildAction.Equals("None"))
450450
{
451-
string include, copyToOutputDirectory;
452-
ReadIncludeContent(io, out include, out copyToOutputDirectory);
451+
string include, link, copyToOutputDirectory;
452+
ReadIncludeContent(io, out include, out link, out copyToOutputDirectory);
453453

454454
if (!string.IsNullOrEmpty(copyToOutputDirectory) && !copyToOutputDirectory.Equals("Never"))
455455
{
456456
var sourceFilePath = Path.GetDirectoryName(projectFilePath);
457457
sourceFilePath += "\\" + include;
458458

459-
OnCopy(sourceFilePath);
459+
var sourceFileArg = (link == null) ? sourceFilePath : sourceFilePath + ";" + link;
460+
OnCopy(sourceFileArg);
460461
}
461462
}
462463
else if (buildAction.Equals("Compile"))
463464
{
464-
string include, name, importer, processor;
465+
string include, link, name, importer, processor;
465466
string[] processorParams;
466-
ReadIncludeCompile(io, out include, out name, out importer, out processor, out processorParams);
467+
ReadIncludeCompile(io, out include, out link, out name, out importer, out processor, out processorParams);
467468

468469
Importer = importer;
469470
Processor = processor;
@@ -476,7 +477,8 @@ public void ImportProject(string projectFilePath)
476477
var sourceFilePath = Path.GetDirectoryName(projectFilePath);
477478
sourceFilePath += "\\" + include;
478479

479-
OnBuild(sourceFilePath);
480+
var sourceFileArg = (link == null) ? sourceFilePath : sourceFilePath + ";" + link;
481+
OnBuild(sourceFileArg);
480482
}
481483
}
482484
}
@@ -511,8 +513,9 @@ private void ReadIncludeReference(XmlReader io, out string include, out string h
511513
}
512514
}
513515

514-
private void ReadIncludeContent(XmlReader io, out string include, out string copyToOutputDirectory)
516+
private void ReadIncludeContent(XmlReader io, out string include, out string link, out string copyToOutputDirectory)
515517
{
518+
link = null;
516519
copyToOutputDirectory = null;
517520
include = io.GetAttribute("Include").Unescape();
518521

@@ -527,6 +530,10 @@ private void ReadIncludeContent(XmlReader io, out string include, out string cop
527530
{
528531
switch (io.LocalName)
529532
{
533+
case "Link":
534+
io.Read();
535+
link = io.Value.Unescape();
536+
break;
530537
case "CopyToOutputDirectory":
531538
io.Read();
532539
copyToOutputDirectory = io.Value.Unescape();
@@ -539,11 +546,13 @@ private void ReadIncludeContent(XmlReader io, out string include, out string cop
539546

540547
private void ReadIncludeCompile(XmlReader io,
541548
out string include,
549+
out string link,
542550
out string name,
543551
out string importer,
544552
out string processor,
545553
out string[] processorParams)
546554
{
555+
link = null;
547556
name = null;
548557
importer = null;
549558
processor = null;
@@ -562,6 +571,10 @@ private void ReadIncludeCompile(XmlReader io,
562571
{
563572
switch (io.LocalName)
564573
{
574+
case "Link":
575+
io.Read();
576+
link = io.Value.Unescape();
577+
break;
565578
case "Name":
566579
io.Read();
567580
name = io.Value.Unescape();

0 commit comments

Comments
 (0)