コード例 #1
0
        /// <summary>
        /// Creates and returns a minimal project file that has imported the ImportsBefore targets file
        /// </summary>
        /// <param name="preImportProperties">Any properties that need to be set before the C# targets are imported. Can be null.</param>
        private ProjectRootElement CreateImportsBeforeTestProject(IDictionary <string, string> preImportProperties)
        {
            // Create a dummy SonarQube analysis targets file
            string dummyAnalysisTargets = EnsureDummyIntegrationTargetsFileExists();

            // Locate the real "ImportsBefore" target file
            string importsBeforeTargets = Path.Combine(TestUtils.GetTestSpecificFolderName(this.TestContext), TargetConstants.ImportsBeforeFile);

            Assert.IsTrue(File.Exists(importsBeforeTargets), "Test error: the SonarQube imports before target file does not exist. Path: {0}", importsBeforeTargets);

            string projectName        = this.TestContext.TestName + ".proj";
            string testSpecificFolder = TestUtils.EnsureTestSpecificFolder(this.TestContext);
            string fullProjectPath    = Path.Combine(testSpecificFolder, projectName);

            ProjectRootElement root = BuildUtilities.CreateMinimalBuildableProject(preImportProperties, false /* not a VB project */, importsBeforeTargets);

            root.AddProperty(TargetProperties.ProjectGuid, Guid.NewGuid().ToString("D"));

            root.Save(fullProjectPath);
            this.TestContext.AddResultFile(fullProjectPath);

            return(root);
        }