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

[ClickOnce] Fix BootstrapperBuilder code to correctly return the list of products available in the packages folder #10093

Merged
merged 1 commit into from
Apr 30, 2024
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
77 changes: 20 additions & 57 deletions src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,81 +829,44 @@ private XmlDocument LoadAndValidateXmlDocument(string filePath, bool validateFil

if (fileExists)
{
var xmlTextReader = new XmlTextReader(filePath) { DtdProcessing = DtdProcessing.Ignore };

XmlReader xmlReader = xmlTextReader;

XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.DtdProcessing = DtdProcessing.Ignore;
if (validate)
{
#pragma warning disable 618 // Using XmlValidatingReader. TODO: We need to switch to using XmlReader.Create() with validation.
using var validatingReader = new XmlValidatingReader(xmlReader);
#pragma warning restore 618
var xrSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true };
FileStream fs = File.OpenRead(schemaPath);
using (XmlReader xr = XmlReader.Create(fs, xrSettings))
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.XmlResolver = null;
xmlReaderSettings.ValidationEventHandler += results.SchemaValidationEventHandler; ;
xmlReaderSettings.Schemas.Add(null, schemaPath);
}

using (StreamReader streamReader = new StreamReader(filePath))
{
using (XmlReader xmlReader = XmlReader.Create(streamReader, xmlReaderSettings, filePath))
{
try
{
// first, add our schema to the validating reader's collection of schemas
var xmlSchema = validatingReader.Schemas.Add(null, xr);

// if our schema namespace gets out of sync,
// then all of our calls to SelectNodes and SelectSingleNode will fail
Debug.Assert((xmlSchema != null) &&
string.Equals(schemaNamespace, xmlSchema.TargetNamespace, StringComparison.Ordinal),
System.IO.Path.GetFileName(schemaPath) + " and BootstrapperBuilder.vb have mismatched namespaces, so the BootstrapperBuilder will fail to work.");

// if we're supposed to be validating, then hook up our handler
validatingReader.ValidationEventHandler += results.SchemaValidationEventHandler;

// switch readers so the doc does the actual read over the validating
// reader so we get validation events as we load the document
xmlReader = validatingReader;
Debug.Assert(_document != null, "our document should have been created by now!");
xmlDocument = new XmlDocument(_document.NameTable);
xmlDocument.Load(xmlReader);
}
catch (XmlException ex)
{
Debug.Fail("Failed to load schema '" + schemaPath + "' due to the following exception:\r\n" + ex.Message);
validate = false;
Debug.Fail("Failed to load document '" + filePath + "' due to the following exception:\r\n" + ex.Message);
return null;
}
catch (System.Xml.Schema.XmlSchemaException ex)
{
Debug.Fail("Failed to load schema '" + schemaPath + "' due to the following exception:\r\n" + ex.Message);
validate = false;
Debug.Fail("Failed to load document '" + filePath + "' due to the following exception:\r\n" + ex.Message);
return null;
}
}
}

try
{
Debug.Assert(_document != null, "our document should have been created by now!");
xmlDocument = new XmlDocument(_document.NameTable);
xmlDocument.Load(xmlReader);
}
catch (XmlException ex)
{
Debug.Fail("Failed to load document '" + filePath + "' due to the following exception:\r\n" + ex.Message);
return null;
}
catch (System.Xml.Schema.XmlSchemaException ex)
{
Debug.Fail("Failed to load document '" + filePath + "' due to the following exception:\r\n" + ex.Message);
return null;
}
finally
{
xmlReader.Close();
}

// Note that the xml document's default namespace must match the schema namespace
// or none of our SelectNodes/SelectSingleNode calls will succeed
Debug.Assert(xmlDocument.DocumentElement != null &&
string.Equals(xmlDocument.DocumentElement.NamespaceURI, schemaNamespace, StringComparison.Ordinal),
"'" + xmlDocument.DocumentElement.NamespaceURI + "' is not '" + schemaNamespace + "'...");

if ((xmlDocument.DocumentElement == null) ||
(!string.Equals(xmlDocument.DocumentElement.NamespaceURI, schemaNamespace, StringComparison.Ordinal)))
{
}
string.Equals(xmlDocument.DocumentElement.NamespaceURI, schemaNamespace, StringComparison.Ordinal),
"'" + xmlDocument.DocumentElement.NamespaceURI + "' is not '" + schemaNamespace + "'...");
}
}

Expand Down
Loading