예제 #1
0
        /// <summary>
        /// Used for validating the project (file) and its imported files against a designated schema.
        ///
        /// PERF NOTE: this property helps to delay creation of the ProjectSchemaValidationHandler object
        /// </summary>
        internal ProjectSchemaValidationHandler SchemaValidator(BuildEventContext buildEventContext)
        {
            if (schemaValidator == null)
            {
                schemaValidator = new ProjectSchemaValidationHandler(buildEventContext, loggingServices, toolset.ToolsPath);
            }

            return(schemaValidator);
        }
        public void VerifyInvalidProjectSchema
            (
            )
        {
            string[] msbuildTempXsdFilenames = new string[] {};
            try
            {
                // Create schema files in the temp folder
                msbuildTempXsdFilenames = PrepareSchemaFiles();

                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <MyInvalidTag/>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine buildEngine = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, buildEngine.LoggingServices, @"c:\");

                try
                {
                    validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents), 
                        msbuildTempXsdFilenames[0]);
                }
                catch (InvalidProjectFileException e)
                {
                    Assertion.AssertEquals(e.BaseMessage, ResourceUtilities.FormatResourceString("ProjectSchemaErrorHalt"));

                    throw;
                }
            }
            finally
            {
                CleanupSchemaFiles(msbuildTempXsdFilenames);
            }
        }
        public void VerifyInvalidSchemaItself1
            (
            )
        {
            string invalidSchemaFile = null;
            try
            {
                // Create schema files in the temp folder
                invalidSchemaFile = Path.GetTempFileName();

                File.WriteAllText(invalidSchemaFile, "<this_is_invalid_schema_content/>");
                
                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine buildEngine = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, buildEngine.LoggingServices, @"c:\");

                try
                {
                    validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents), invalidSchemaFile);
                }
                catch (InvalidProjectFileException e)
                {
                    Console.WriteLine(e.Message);
                    Assertion.Assert(e.ErrorCode.Contains("MSB4070") || e.BaseMessage.Contains("MSB4070"));

                    throw;
                }
            }
            finally
            {
                if (invalidSchemaFile != null) File.Delete(invalidSchemaFile);
            }
        }
        public void VerifyValidProjectSchema
            (
            )
        {
            string[] msbuildTempXsdFilenames = new string[] {};
            try
            {
                // Create schema files in the temp folder
                msbuildTempXsdFilenames = PrepareSchemaFiles();

                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine e = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, e.LoggingServices, @"c:\");

                validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents), 
                    msbuildTempXsdFilenames[0]);
            }
            finally
            {
                CleanupSchemaFiles(msbuildTempXsdFilenames);
            }
        }
        public void VerifyInvalidSchemaItself2
            (
            )
        {
            string invalidSchemaFile = null;
            try
            {
                // Create schema files in the temp folder
                invalidSchemaFile = Path.GetTempFileName();

                File.WriteAllText(invalidSchemaFile, @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema targetNamespace=""http://schemas.microsoft.com/developer/msbuild/2003"" xmlns:msb=""http://schemas.microsoft.com/developer/msbuild/2003"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" elementFormDefault=""qualified"">
    <xs:element name=""Project"">
        <xs:complexType>
            <xs:sequence>
                <xs:group ref=""x"" minOccurs=""0"" maxOccurs=""unbounded""/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

");

                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine buildEngine = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, buildEngine.LoggingServices, @"c:\");

                try
                {
                    validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents), invalidSchemaFile);
                }
                catch (InvalidProjectFileException e)
                {
                    Console.WriteLine(e.Message);
                    Assertion.Assert(e.ErrorCode.Contains("MSB4070") || e.BaseMessage.Contains("MSB4070"));

                    throw;
                }
            }
            finally
            {
                if (invalidSchemaFile != null) File.Delete(invalidSchemaFile);
            }
        }
예제 #6
0
        /// <summary>
        /// Used for validating the project (file) and its imported files against a designated schema.
        ///
        /// PERF NOTE: this property helps to delay creation of the ProjectSchemaValidationHandler object
        /// </summary>
        internal ProjectSchemaValidationHandler SchemaValidator(BuildEventContext buildEventContext)
        {
            if (schemaValidator == null)
            {
                schemaValidator = new ProjectSchemaValidationHandler(buildEventContext, loggingServices, toolset.ToolsPath);
            }

            return schemaValidator;
        }