/// <summary> /// Validates a project file against the given schema. If no schema is given, validates /// against the default schema /// </summary> /// <param name="projectFile">Path of the file to validate.</param> /// <param name="schemaFile">Can be null.</param> /// <param name="binPath">Path to the framework directory where the default schema for /// this ToolsVersion can be found.</param> /// <returns>True if the project was successfully validated against the given schema, false otherwise</returns> internal static void VerifyProjectSchema ( string projectFile, string schemaFile, string binPath ) { ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile"); ErrorUtilities.VerifyThrowArgumentNull(binPath, "binPath"); if ((schemaFile == null) || (schemaFile.Length == 0)) { schemaFile = Path.Combine(binPath, "Microsoft.Build.xsd"); } if (FileSystems.Default.FileExists(schemaFile)) { // Print the schema file we're using, particularly since it can vary // according to the toolset being used Console.WriteLine(AssemblyResources.GetString("SchemaFileLocation"), schemaFile); } else { // If we've gotten to this point, there is no schema to validate against -- just exit. InitializationException.Throw ( ResourceUtilities.FormatResourceString("SchemaNotFoundErrorWithFile", schemaFile), null /* No associated command line switch */ ); } ProjectSchemaValidationHandler validationHandler = new ProjectSchemaValidationHandler(); validationHandler.VerifyProjectSchema(projectFile, schemaFile); }
/// <summary> /// Validates a project file against the given schema. If no schema is given, validates /// against the default schema /// </summary> /// <param name="projectFile">Path of the file to validate.</param> /// <param name="schemaFile">Can be null.</param> /// <param name="binPath">Path to the framework directory where the default schema for /// this ToolsVersion can be found.</param> /// <returns>True if the project was successfully validated against the given schema, false otherwise</returns> internal static void VerifyProjectSchema ( string projectFile, string schemaFile, string binPath ) { ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile"); ErrorUtilities.VerifyThrowArgumentNull(binPath, "binPath"); if ((schemaFile == null) || (schemaFile.Length == 0)) { schemaFile = Path.Combine(binPath, "Microsoft.Build.xsd"); } if (File.Exists(schemaFile)) { // Print the schema file we're using, particularly since it can vary // according to the toolset being used Console.WriteLine(AssemblyResources.GetString("SchemaFileLocation"), schemaFile); } else { // If we've gotten to this point, there is no schema to validate against -- just exit. InitializationException.Throw ( ResourceUtilities.FormatResourceString("SchemaNotFoundErrorWithFile", schemaFile), null /* No associated command line switch */ ); } ProjectSchemaValidationHandler validationHandler = new ProjectSchemaValidationHandler(); validationHandler.VerifyProjectSchema(projectFile, schemaFile); }