I'm working on a VS 2012 Pro Addin in C#. One of the requested features is to suppress a certain warning for XML documents within a certain type of VS project. All of the XML documents in our projects of this type contain a reference to a schema that has a known XML warning:
The complex type 'wxl:foo' has already been declared.
Because the schema contains this error, all XML documents containing a reference to it raise the following error:
The schema referenced from this location in your document contains errors.
Unfortunately, we do not have the ability to correct this error in the schema because of the outside system that it is attached to. (I've attempted to get the developers to correct it at the source, with no luck.) So, my solution is to simply suppress the error. It does not cause any compiler issues, but makes some of our newer developers nervous when they see the warning message.
Now, I already have known working code for determining when a project has been loaded, and if that project is of the type it needs to be.
I've added the following method that will only be called if the above statement is true:
private static void SuppressWarnings(params string[] newErrorCodes)
{
var noWarnProperty = _project.ConfigurationManager.ActiveConfiguration.Properties.Item("NoWarn");
string errorCodesToSuppress = JoinExistingAndNewErrorCodes(newErrorCodes.ToList(), noWarnProperty.Value);
noWarnProperty.Value = errorCodesToSuppress;
}
private static string JoinExistingAndNewErrorCodes(List<string> errorCodes, string existingErrorCodes)
{
List<string> existingErrors = existingErrorCodes.Split(';').ToList();
errorCodes.AddRange(existingErrors);
errorCodes = errorCodes.Select(errorCode => errorCode.Trim(' ')).ToList();
errorCodes.RemoveAll(String.IsNullOrWhiteSpace);
errorCodes = errorCodes.Distinct().ToList();
return String.Join(";", errorCodes);
}
My problem is that I cannot find the error codes that I need to suppress. I've searched StackOverflow, the MSDN website, and the VS help documentation. I've found a list of many error codes (which MS seems to have stopped publishing after VS 2008), but none that do what I need.
Did I waste my time with the above solution, or have I just completely overlooked the codes? I'm hoping the latter is true.
No comments:
Post a Comment