/// <summary>
        /// Gets a Project that imports another Project
        /// </summary>
        /// <param name="importProjectContents">Project Contents of the imported Project, to get default content, pass in an empty string</param>
        /// <param name="parentProjectContents">Project Contents of the Parent Project, to get default content, pass in an empty string</param>
        /// <returns>Project</returns>
        private Project GetProjectThatImportsAnotherProject(string importProjectContents, string parentProjectContents)
        {
            if (String.IsNullOrEmpty(importProjectContents))
            {
                importProjectContents = @" 
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                        <ItemGroup>
                            <nImported Include='iImported' />
                            <n1Imported Include='i1Imported' Exclude='e1Imported' Condition=""'a2' == 'b2'"">
                                <n1ImportedMeta1>n1Importedvalue1</n1ImportedMeta1>
                                <n1ImportedMeta2>n1Importedvalue2</n1ImportedMeta2>
                            </n1Imported>
                            <n2Imported Include='i2Imported' />
                            <n3Imported Include='i3Imported'>
                                <n3ImportedMeta1>n3Importedvalue1</n3ImportedMeta1>
                            </n3Imported>
                        </ItemGroup>
                    </Project>
                ";
            }

            if (String.IsNullOrEmpty(parentProjectContents))
            {
                parentProjectContents = @" 
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                        <ItemGroup>
                            <n1Main Include='iMain' />
                            <n2Main Include='iMain' >
                                <n2MainMeta>n2Mainvalue</n2MainMeta>
                            </n2Main>
                        </ItemGroup>
                        <Import Project='import.proj' />
                    </Project>
                ";
            }

            ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", importProjectContents);
            ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", parentProjectContents);
            return(ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main.proj", null));
        }
Esempio n. 2
0
        public void BothBaseOutputPathAndOutputPathWereSpecified()
        {
            // Arrange
            var baseOutputPath = Path.Combine("build", "bin");
            var outputPath     = Path.Combine("bin", "Debug");
            var outputPathAlt  = Path.Combine("bin", "Release");

            var projectFilePath = ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath,
                                                                                      $@"<Project DefaultTargets=`Build` xmlns=`msbuildnamespace` ToolsVersion=`msbuilddefaulttoolsversion`>

    <Import Project=`$(MSBuildToolsPath)\Microsoft.Common.props`/>

    <PropertyGroup>
        <Platform>AnyCPU</Platform>
        <Configuration>Debug</Configuration>
    </PropertyGroup>

    <PropertyGroup>
        <BaseOutputPath>{baseOutputPath}</BaseOutputPath>
        <OutputPath Condition=`'$(Platform)|$(Configuration)' == 'AnyCPU|Debug'`>{outputPath}</OutputPath>
        <OutputPath Condition=`'$(Platform)|$(Configuration)' == 'AnyCPU|Release'`>{outputPathAlt}</OutputPath>
    </PropertyGroup>

    <Import Project=`$(MSBuildToolsPath)\Microsoft.Common.targets`/>
    <Target Name=`Build`/>

</Project>");

            // Act
            Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(projectFilePath, touchProject: false);

            project.Build(new MockLogger(_output)).ShouldBeTrue();

            // Assert
            project.GetPropertyValue("BaseOutputPath").ShouldBe(baseOutputPath.WithTrailingSlash());
            project.GetPropertyValue("OutputPath").ShouldBe(outputPath.WithTrailingSlash());
            project.GetPropertyValue("BaseOutputPathWasSpecified").ShouldBe("true");
            project.GetPropertyValue("_OutputPathWasMissing").ShouldBe(string.Empty);
        }