public void ImportFromExtensionsPathNotFound()
        {
            string extnDir1 = null;
            string mainProjectPath = null;

            try {
                extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1());
                mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent());

                var projColln = new ProjectCollection();
                projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistant")));
                var logger = new MockLogger();
                projColln.RegisterLogger(logger);

                Assert.Throws<InvalidProjectFileException>(() => projColln.LoadProject(mainProjectPath));

                logger.AssertLogContains("MSB4226");
            } finally {
                if (mainProjectPath != null)
                {
                    FileUtilities.DeleteNoThrow(mainProjectPath);
                }
                if (extnDir1 != null)
                {
                    FileUtilities.DeleteDirectoryNoThrow(extnDir1, recursive: true);
                }
            }
        }
 public void Initialize()
 {
     engine = new Engine();
     myProject = new Project(engine);
     myLogger = new MockLogger();
     myProject.ParentEngine.RegisterLogger(myLogger);
 }
 public void Cleanup()
 {
     engine.UnloadProject(myProject);
     engine.UnregisterAllLoggers();
     engine = null;
     myProject = null;
     myLogger = null;
 }
Exemple #4
0
 public MockEngine(bool logToConsole)
 {
     mockLogger = new MockLogger();
     this.logToConsole = logToConsole;
     this.engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));
     this.engine.RegisterLogger(new ConsoleLogger());
     this.engine.RegisterLogger(mockLogger);
     engineGlobalProperties = new BuildPropertyGroup();
 }
Exemple #5
0
        public void Initialize()
        {
            ObjectModelHelpers.DeleteTempProjectDirectory();

            engine = new Engine();
            engine.DefaultToolsVersion = "4.0";
            project = new Project(engine);
            logger = new MockLogger();
            project.ParentEngine.RegisterLogger(logger);
        }
Exemple #6
0
        public void InvalidToolPath()
        {
            //Note Engine's BinPath is distinct from the ToolsVersion's ToolsPath
            Engine e = new Engine();
            MockLogger mockLogger = new MockLogger();
            e.RegisterLogger(mockLogger);
            ToolsetState t = new ToolsetState(e, new Toolset("toolsversionname", "invalid||path"), new GetFiles(this.getFiles), new LoadXmlFromPath(this.loadXmlFromPath));

            TaskRegistry taskRegistry = (TaskRegistry) t.GetTaskRegistry(null);

            Console.WriteLine(mockLogger.FullLog);
            Assert.AreEqual(1, mockLogger.WarningCount, "Expected a warning for invalid character in toolpath"); 
        }
        public void AddNewErrorWarningMessageElement()
        {
            MockLogger logger = new MockLogger();
            Project project = ObjectModelHelpers.CreateInMemoryProject(
                "<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>" +
                    "<Target Name=`Build`>" +
                    "</Target>" +
                "</Project>",
                logger);

            Target target = project.Targets["Build"];

            SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.message, true, "SolutionVenusProjectNoClean");
            SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.warning, true, "SolutionParseUnknownProjectType", "proj1.csproj");
            SolutionWrapperProject.AddErrorWarningMessageElement(target, XMakeElements.error, true, "SolutionVCProjectNoPublish");

            project.Build(null, null);

            string code = null;
            string keyword = null;
            string text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionParseUnknownProjectType", "proj1.csproj");

            // check the error event
            Assertion.AssertEquals(1, logger.Warnings.Count);
            BuildWarningEventArgs warning = logger.Warnings[0];

            Assertion.AssertEquals(text, warning.Message);
            Assertion.AssertEquals(code, warning.Code);
            Assertion.AssertEquals(keyword, warning.HelpKeyword);

            code = null;
            keyword = null;
            text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionVCProjectNoPublish");

            // check the warning event
            Assertion.AssertEquals(1, logger.Errors.Count);
            BuildErrorEventArgs error = logger.Errors[0];

            Assertion.AssertEquals(text, error.Message);
            Assertion.AssertEquals(code, error.Code);
            Assertion.AssertEquals(keyword, error.HelpKeyword);

            code = null;
            keyword = null;
            text = ResourceUtilities.FormatResourceString(out code, out keyword, "SolutionVenusProjectNoClean");

            // check the message event
            Assertion.Assert("Log should contain the regular message", logger.FullLog.Contains(text));
        }
        public void TargetARM()
        {
            string file = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                file = Helpers.CreateFiles("class1.cs")[0];

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>Library</OutputType>
                        <Configuration>Debug</Configuration>
                        <PlatformTarget>arm</PlatformTarget>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + file + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` />
                    </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogContains(" /platform:arm ");
            }
            finally
            {
                if (file != null)
                {
                    File.Delete(file);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
Exemple #9
0
        public void WarningLoggedIfNoDefaultTasksFound()
        {
            //Note Engine's BinPath is distinct from the ToolsVersion's ToolsPath
            Engine e = new Engine();
            MockLogger mockLogger = new MockLogger();
            e.RegisterLogger(mockLogger);

            ToolsetState t = new ToolsetState(e, new Toolset("toolsversionname", "c:\\directory1\\directory2\\doesntexist"), new GetFiles(this.getFiles), new LoadXmlFromPath(this.loadXmlFromPath));

            TaskRegistry taskRegistry = (TaskRegistry) t.GetTaskRegistry(null);

            string[] unexpectedRegisteredTasks = { "a1", "a2", "a3", "a4", "b1", "c1", "d1", "e1", "f1", "g1", "g2", "g3", "11", "12", "13", "21" };

            Assert.AreEqual(1, mockLogger.WarningCount, "Expected 1 warning logged!");
            foreach (string unexpectedRegisteredTask in unexpectedRegisteredTasks)
            {
                Hashtable registeredTasks;
                Assert.IsFalse(taskRegistry.FindRegisteredTasks(unexpectedRegisteredTask, true, out registeredTasks),
                               String.Format("Unexpected task '{0}' registered!", unexpectedRegisteredTask));
            }
        }
Exemple #10
0
        public void Basic()
        {
            MockLogger l = new MockLogger();
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> 
                   <Target Name='CleanUp'>
                      <Message Text='CleanUp-was-called.'/>
                   </Target>
                   <Target Name='Build'>
                      <Error Text='This is an error.'/>
                      <OnError ExecuteTargets='CleanUp'/>
                   </Target>
                </Project>",
                l
            );

            p.Build(new string [] {"Build"}, null);

            Assertion.Assert("Expected one error because 'Build' failed.", l.ErrorCount==1);
            Assertion.Assert("The CleanUp target should have been called.", (l.FullLog.IndexOf("CleanUp-was-called") != -1));
        }
        public void TestTargetFrameworkPaths()
        {
            string[] targetFrameworkVersions = { "v2.0", "v3.0", "v3.5", "v4.0", "v4.5", "" };
            foreach (var version in targetFrameworkVersions)
            {
                MockLogger logger = new MockLogger();
                string projString = ObjectModelHelpers.CleanupFileContents(
                    @"
<Project ToolsVersion=`msbuilddefaulttoolsversion` DefaultTargets=`GetPaths` xmlns=`msbuildnamespace`>
  <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.targets` />
  <Target
      Name='GetPaths'
      DependsOnTargets='GetFrameworkPaths'>
    <Message Text='Target Framework Folder = @(_TargetedFrameworkDirectoryItem)' />
  </Target>
</Project>"
                   );
                Project project = ObjectModelHelpers.CreateInMemoryProject(
                 projString,
                 logger
                 );

                project.SetProperty("TargetFrameworkVersion", version);
                project.Build();

                string targetFrameworkVersion = project.GetPropertyValue("TargetFrameworkVersion");
                string msbuildFrameworkToolsRoot = project.GetPropertyValue("MSBuildFrameworkToolsRoot");

                if (targetFrameworkVersion.Equals("v2.0"))
                {
                    if (FrameworkLocationHelper.PathToDotNetFrameworkV20 != null)
                    {
                        logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + FrameworkLocationHelper.PathToDotNetFrameworkV20);
                    }
                    else
                    {
                        // If Framework v2.0 isn't present we use the hard coded version for this validation
                        logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + msbuildFrameworkToolsRoot + "v2.0.50727");
                    }
                }
                else if (targetFrameworkVersion.Equals("v3.0") || targetFrameworkVersion.Equals("v3.5"))
                {
                    logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + msbuildFrameworkToolsRoot + "\\" + targetFrameworkVersion);
                }
                else if (targetFrameworkVersion.Equals("v4.0"))
                {
                    logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + FrameworkLocationHelper.PathToDotNetFrameworkV40);
                }
                else if (targetFrameworkVersion.Equals("v4.5"))
                {
                    logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + FrameworkLocationHelper.PathToDotNetFrameworkV45);
                }
                else if (String.IsNullOrEmpty(targetFrameworkVersion))
                {
                    logger.AssertLogContains(false/* not case sensitive */, "Target Framework Folder = " + FrameworkLocationHelper.PathToDotNetFrameworkV45);
                }
            }
        }
        public void TestGetFrameworkPaths()
        {
            MockLogger logger = new MockLogger();

            Project project = ObjectModelHelpers.CreateInMemoryProject(
                @"
<Project ToolsVersion=`msbuilddefaulttoolsversion` DefaultTargets=`GetPaths` xmlns=`msbuildnamespace`>
  <Target Name=`GetPaths` DependsOnTargets=`GetFrameworkPaths`>
    <Message Text=`Framework 4.0 = @(_TargetFramework40DirectoryItem)` Importance=`High`/>
    <Message Text=`Framework 3.5 = @(_TargetFramework35DirectoryItem)` Importance=`High`/>
    <Message Text=`Framework 3.0 = @(_TargetFramework30DirectoryItem)` Importance=`High`/>
    <Message Text=`Framework 2.0 = @(_TargetFramework20DirectoryItem)` Importance=`High`/>
  </Target>
  <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.targets` />
</Project>",
             logger
             );

            project.Build();

            logger.AssertLogContains(false/* not case sensitive */, "Framework 4.0 = " + FrameworkLocationHelper.PathToDotNetFrameworkV40);

            // Only check .NET 3.5 and below if they're actually on the box.
            if (FrameworkLocationHelper.PathToDotNetFrameworkV35 != null)
            {
                logger.AssertLogContains(false/* not case sensitive */, "Framework 3.5 = " + FrameworkLocationHelper.PathToDotNetFrameworkV35);
                logger.AssertLogContains(false/* not case sensitive */, "Framework 3.0 = " + FrameworkLocationHelper.PathToDotNetFrameworkV30);
                logger.AssertLogContains(false/* not case sensitive */, "Framework 2.0 = " + FrameworkLocationHelper.PathToDotNetFrameworkV20);
            }
        }
        public void AnyCPUJupiterProjectWithNoExplicitOutputTypeIs32BitPreferred()
        {
            string file = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                file = Helpers.CreateFiles("class1.cs")[0];

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <Configuration>Debug</Configuration>
                        <PlatformTarget>AnyCPU</PlatformTarget>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + file + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets` Condition=`Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                      <!-- Fall back to CSharp targets for the sake of this test if the Jupiter targets don't exist, since what we're testing can be equally well resolved by either -->
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` Condition=`!Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                   </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogContains(" /platform:anycpu32bitpreferred");
            }
            finally
            {
                if (file != null)
                {
                    File.Delete(file);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
        public void TestSkipInvalidConfigurationsCase()
        {
            string tmpFileName = Path.GetTempFileName();

            File.Delete(tmpFileName);
            string projectFilePath = tmpFileName + ".sln";

            string solutionContents =
                @"
                Microsoft Visual Studio Solution File, Format Version 9.00
                # Visual Studio 2005
                Project('{E24C65DC-7377-472B-9ABA-BC803B73C61A}') = 'C:\solutions\WebSite2\', '..\..\solutions\WebSite2\', '{F90528C4-6989-4D33-AFE8-F53173597CC2}'
                    ProjectSection(WebsiteProperties) = preProject
                        Debug.AspNetCompiler.VirtualPath = '/WebSite2'
                        Debug.AspNetCompiler.PhysicalPath = '..\..\solutions\WebSite2\'
                        Debug.AspNetCompiler.TargetPath = 'PrecompiledWeb\WebSite2\'
                        Debug.AspNetCompiler.Updateable = 'true'
                        Debug.AspNetCompiler.ForceOverwrite = 'true'
                        Debug.AspNetCompiler.FixedNames = 'true'
                        Debug.AspNetCompiler.Debug = 'True'
                        Release.AspNetCompiler.VirtualPath = '/WebSite2'
                        Release.AspNetCompiler.PhysicalPath = '..\..\solutions\WebSite2\'
                        Release.AspNetCompiler.TargetPath = 'PrecompiledWeb\WebSite2\'
                        Release.AspNetCompiler.Updateable = 'true'
                        Release.AspNetCompiler.ForceOverwrite = 'true'
                        Release.AspNetCompiler.FixedNames = 'true'
                        Release.AspNetCompiler.Debug = 'False'
                        VWDPort = '2776'
                        DefaultWebSiteLanguage = 'Visual C#'
                    EndProjectSection
                EndProject
                Global
                    GlobalSection(SolutionConfigurationPlatforms) = preSolution
                        Debug|Any CPU = Debug|Any CPU
                    EndGlobalSection
                    GlobalSection(ProjectConfigurationPlatforms) = postSolution
                        {F90528C4-6989-4D33-AFE8-F53173597CC2}.Debug|Any CPU.ActiveCfg = Debug|.NET
                        {F90528C4-6989-4D33-AFE8-F53173597CC2}.Debug|Any CPU.Build.0 = Debug|.NET
                    EndGlobalSection
                EndGlobal";

            File.WriteAllText(projectFilePath, solutionContents.Replace('\'', '"'));

            try
            {
                MockLogger logger = new MockLogger();
                Engine     engine = new Engine();
                engine.RegisterLogger(logger);

                Project solutionWrapperProject = new Project(engine);
                solutionWrapperProject.Load(projectFilePath);

                solutionWrapperProject.SetProperty("Configuration", "Nonexistent");
                solutionWrapperProject.SetProperty("SkipInvalidConfigurations", "true");
                solutionWrapperProject.ToolsVersion = "4.0";

                // Build should complete successfully even with an invalid solution config if SkipInvalidConfigurations is true
                Assertion.AssertEquals(true, solutionWrapperProject.Build(null, null));

                // We should get the invalid solution configuration warning
                Assertion.AssertEquals(1, logger.Warnings.Count);
                BuildWarningEventArgs warning = logger.Warnings[0];

                // Don't look at warning.Code here -- it may be null if PseudoLoc has messed
                // with our resource strings. The code will still be in the log -- it just wouldn't get
                // pulled out into the code field.
                logger.AssertLogContains("MSB4126");

                // No errors expected
                Assertion.AssertEquals(0, logger.Errors.Count);
            }
            finally
            {
                File.Delete(projectFilePath);
            }
        }
        public void VerifyGetInstalledSDKLocations2()
        {
            string testDirectoryRoot = Path.Combine(Path.GetTempPath(), "VerifyGetInstalledSDKLocations2");
            string platformDirectory = Path.Combine(testDirectoryRoot, "MyPlatform\\8.0\\");
            string sdkDirectory = Path.Combine(platformDirectory, "ExtensionSDKs\\SDkWithManifest\\2.0\\");

            string tempProjectContents = ObjectModelHelpers.CleanupFileContents(@"
             <Project DefaultTargets=""ExpandSDKReferenceAssemblies"" ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
                 <PropertyGroup>
                    <TargetPlatformIdentifier>MyPlatform</TargetPlatformIdentifier> 
                    <TargetPlatformVersion>8.0</TargetPlatformVersion>" +
                   @"<SDKDirectoryRoot>" + testDirectoryRoot + "</SDKDirectoryRoot>" +
                    @"<SDKLocation1>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformExtensionSDKLocation('SDkWithManifest, Version=2.0','MyPlatform','8.0', '$(SDKDirectoryRoot)',''))</SDKLocation1>
                      <SDKLocation2>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformExtensionSDKLocation('SDkWithManifest, Version=V2.0','MyPlatform','8.0', '$(SDKDirectoryRoot)',''))</SDKLocation2>                 
                      <SDKLocation3>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('MyPlatform','8.0', '$(SDKDirectoryRoot)',''))</SDKLocation3>
                      <SDKName>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName('MyPlatform','8.0', '$(SDKDirectoryRoot)', ''))</SDKName>
                 </PropertyGroup>

                 <Import Project=""$(MSBuildBinPath)\Microsoft.Common.targets""/>
              </Project>");

            string platformSDKManifestContents = @"<FileList
                    DisplayName = ""My cool platform SDK!"">
                </FileList>";

            try
            {
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", "true");
                if (Directory.Exists(testDirectoryRoot))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDirectoryRoot, true);
                }

                Directory.CreateDirectory(testDirectoryRoot);
                Directory.CreateDirectory(sdkDirectory);
                File.WriteAllText(Path.Combine(platformDirectory, "sdkManifest.xml"), platformSDKManifestContents);
                File.WriteAllText(Path.Combine(sdkDirectory, "sdkManifest.xml"), "HI");
                string testProjectFile = Path.Combine(testDirectoryRoot, "testproject.csproj");

                File.WriteAllText(testProjectFile, tempProjectContents);

                MockLogger logger = new MockLogger(_output);

                ProjectCollection pc = new ProjectCollection();
                Project project = pc.LoadProject(testProjectFile);
                string propertyValue1 = project.GetPropertyValue("SDKLocation1");
                string propertyValue2 = project.GetPropertyValue("SDKLocation2");
                string propertyValue3 = project.GetPropertyValue("SDKLocation3");
                string sdkName = project.GetPropertyValue("SDKName");

                Assert.True(propertyValue1.Equals(sdkDirectory, StringComparison.OrdinalIgnoreCase));
                Assert.True(propertyValue3.Equals(platformDirectory, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(0, propertyValue2.Length);
                Assert.Equal("My cool platform SDK!", sdkName);
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDDISABLEREGISTRYFORSDKLOOKUP", null);
                if (Directory.Exists(testDirectoryRoot))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDirectoryRoot, true);
                }
            }
        }
        public void VerifyToolsetAndToolLocationHelperAgreeWhenVisualStudioVersionIs10()
        {
            string projectContents = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion='4.0'>
                        <UsingTask TaskName='VerifySdkPaths' TaskFactory='CodeTaskFactory' AssemblyName='Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' >
                         <ParameterGroup>     
                             <Sdk35ToolsPath />
                             <Sdk40ToolsPath />
                             <WindowsSDK80Path />
                          </ParameterGroup>
                            <Task>
                                <Using Namespace='Microsoft.Win32'/>
                                <Code>
                                <![CDATA[
                                    string pathTo35Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdk(TargetDotNetFrameworkVersion.Version35, VisualStudioVersion.Version100);
                                    string pathTo40Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdk(TargetDotNetFrameworkVersion.Version40, VisualStudioVersion.Version100);

                                    pathTo35Sdk = pathTo35Sdk == null ? pathTo35Sdk : Path.Combine(pathTo35Sdk, ""bin\\"");
                                    pathTo40Sdk = pathTo40Sdk == null ? pathTo40Sdk : Path.Combine(pathTo40Sdk, ""bin\\NetFX 4.0 Tools\\"");" +
                                    s_verifyToolsetAndToolLocationHelperProjectCommonContent +
                                  @"return !Log.HasLoggedErrors;
                                ]]>
                              </Code>
                            </Task>
                        </UsingTask>
                        <Target Name='Build'>
                            <VerifySdkPaths Sdk35ToolsPath='$(Sdk35ToolsPath)' Sdk40ToolsPath='$(Sdk40ToolsPath)' WindowsSDK80Path='$(WindowsSDK80Path)' />
                        </Target>
                    </Project>";

            ILogger logger = new MockLogger(_output);
            IDictionary<string, string> globalProperties = new Dictionary<string, string>();
            globalProperties.Add("VisualStudioVersion", "10.0");

            ProjectCollection collection = new ProjectCollection(globalProperties);
            Project p = ObjectModelHelpers.CreateInMemoryProject(collection, projectContents, logger, "4.0");

            bool success = p.Build(logger);

            Assert.True(success); // "Build Failed.  See Std Out for details."
        }
Exemple #17
0
 /// <summary>
 /// Un-registers the existing logger and registers a new copy.
 /// We will use this when we do multiple builds so that we can safely 
 /// assert on log messages for that particular build.
 /// </summary>
 private void ResetLogger()
 {
     engine.UnregisterAllLoggers();
     logger = new MockLogger();
     project.ParentEngine.RegisterLogger(logger);
 }
        public void TargetNamesAlwaysUnescaped_Override()
        {
            Project project = ObjectModelHelpers.CreateInMemoryProject(@"
            <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                <Target Name=`%3B`>
                    <Message Text=`[WRONG]` />
                </Target>
                <Target Name=`;`>
                    <Message Text=`[OVERRIDE]` />
                </Target>
            </Project>
            ");
            MockLogger logger = new MockLogger();

            bool success = project.Build(logger);
            Assert.True(success); // "Build failed.  See Standard Out tab for details"
            logger.AssertLogContains("[OVERRIDE]");
        }
        public void GlobalPropertyWithEscapedCharacters()
        {
            MockLogger logger = new MockLogger();
            Project project = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                    <Target Name=`Build`>
                        <Message Text=`MyGlobalProperty = '$(MyGlobalProperty)'` />
                    </Target>
                </Project>
                ");

            project.SetGlobalProperty("MyGlobalProperty", "foo%253bbar");

            bool success = project.Build(logger);
            Assert.True(success); // "Build failed.  See Standard Out tab for details"

            logger.AssertLogContains("MyGlobalProperty = 'foo%3bbar'");
        }
        public void NoLinkMetadataSynthesisWhenDefinedInProject()
        {
            string[] files = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                files = Helpers.CreateFiles("class1.cs", "File1.txt", "Content1.foo");

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>Library</OutputType>
                        <Configuration>Debug</Configuration>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                        <SynthesizeLinkMetadata>true</SynthesizeLinkMetadata>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + files[0] + @"` />
                        <None Include=`" + files[1] + @"` />
                        <Content Include=`" + files[2] + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` />
                      <Target Name=`AfterBuild`>
                        <Message Text=`%(Compile.Identity): [%(Compile.Link)]` />
                        <Message Text=`%(None.Identity): [%(None.Link)]` />
                        <Message Text=`%(Content.Identity): [%(Content.Link)]` />
                      </Target>
                    </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogContains(String.Format("{0}: []", files[0]));
                logger.AssertLogContains(String.Format("{0}: []", files[1]));
                logger.AssertLogContains(String.Format("{0}: []", files[2]));
            }
            finally
            {
                if (files != null)
                {
                    foreach (string file in files)
                    {
                        File.Delete(file);
                    }
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
        public void SynthesizeLinkMetadataForItemsOnWhitelist()
        {
            string[] files = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");
            string directoryToDelete = null;

            try
            {
                files = Helpers.CreateFiles("class1.cs", "File1.txt", "Content1.foo", "a.proj");

                directoryToDelete = Path.GetDirectoryName(files[0]);
                string subProjectDirectory = Path.Combine(Path.GetDirectoryName(files[0]), "SubFolder");
                Directory.CreateDirectory(subProjectDirectory);

                string classPath = Path.Combine(subProjectDirectory, "Class1.cs");
                string textFilePath = Path.Combine(subProjectDirectory, "File1.txt");
                string contentPath = Path.Combine(subProjectDirectory, "Content1.foo");

                File.Move(files[0], classPath);
                File.Move(files[1], textFilePath);
                File.Move(files[2], contentPath);

                string sharedFilesProjectContents =
                            @"<Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                              <ItemGroup>
                                <Compile Include=`" + classPath + @"` />
                                <None Include=`" + textFilePath + @"` />
                                <Content Include=`" + contentPath + @"` />
                              </ItemGroup>
                           </Project>";

                File.WriteAllText(files[3], ObjectModelHelpers.CleanupFileContents(sharedFilesProjectContents));

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>Library</OutputType>
                        <Configuration>Debug</Configuration>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                        <SynthesizeLinkMetadata>true</SynthesizeLinkMetadata>
                      </PropertyGroup>
                      <Import Project=`" + files[3] + @"` />
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` />
                      <Target Name=`AfterBuild`>
                        <Message Text=`%(Compile.Identity): [%(Compile.Link)]` />
                        <Message Text=`%(None.Identity): [%(None.Link)]` />
                        <Message Text=`%(Content.Identity): [%(Content.Link)]` />
                      </Target>
                    </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogContains(String.Format(@"{0}: []", classPath));
                logger.AssertLogContains(String.Format(@"{0}: [SubFolder\File1.txt]", textFilePath));
                logger.AssertLogContains(String.Format(@"{0}: [SubFolder\Content1.foo]", contentPath));
            }
            finally
            {
                if (directoryToDelete != null)
                {
                    ObjectModelHelpers.DeleteDirectory(directoryToDelete);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
Exemple #22
0
        public void EmptyProjectsParameterResultsInNoop()
        {
            string projectContents = ObjectModelHelpers.CleanupFileContents(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`t` >
	                    <MSBuild Projects=` @(empty) ` />
                    </Target>
                </Project>
                ");

            MockLogger logger = new MockLogger();
            Project project = ObjectModelHelpers.CreateInMemoryProject(projectContents, logger);

            bool success = project.Build();
            Assert.IsTrue(success, "Build failed.  See Standard Out tab for details");
        }
        public void EscapedWildcardsShouldNotBeExpanded_InTaskHost()
        {
            MockLogger logger = new MockLogger();

            try
            {
                // Populate the project directory with three physical files on disk -- a.weirdo, b.weirdo, c.weirdo.
                EscapingInProjectsHelper.CreateThreeWeirdoFiles();
                Project project = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                    <UsingTask TaskName=`Message` AssemblyFile=`$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll` TaskFactory=`TaskHostFactory` />

                    <Target Name=`t`>
                        <ItemGroup>
                            <type Include=`%2A` Exclude=``/>
                        </ItemGroup>
                        <Message Text=`[@(type)]`/>
                    </Target>
                </Project>
                ");

                bool success = project.Build(logger);
                Assert.True(success); // "Build failed.  See Standard Out tab for details"
                logger.AssertLogContains("[*]");
            }
            finally
            {
                EscapingInProjectsHelper.CleanupWeirdoFiles();
            }
        }
Exemple #24
0
 public MockEngine(bool logToConsole)
 {
     _mockLogger = new MockLogger();
     _logToConsole = logToConsole;
 }
        public void SemicolonInConfiguration_UsingTaskHost()
        {
            string originalOverrideTaskHostVariable = Environment.GetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC");

            try
            {
                Environment.SetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC", "1");
                ObjectModelHelpers.DeleteTempProjectDirectory();

                // ---------------------
                // Foo.csproj
                // ---------------------
                ObjectModelHelpers.CreateFileInTempProjectDirectory("foo.csproj", @"
                <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`>
                    <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` />
                    <PropertyGroup>
                        <Configuration Condition=` '$(Configuration)' == '' `>Debug</Configuration>
                        <Platform Condition=` '$(Platform)' == '' `>AnyCPU</Platform>
                        <OutputType>Library</OutputType>
                        <AssemblyName>ClassLibrary16</AssemblyName>
                    </PropertyGroup>
                    <PropertyGroup Condition=` '$(Configuration)|$(Platform)' == 'a%3bb%27c|AnyCPU' `>
                        <OutputPath>bin\a%3bb%27c\</OutputPath>
                    </PropertyGroup>
                    <ItemGroup>
                        <Reference Include=`System` />
                        <Compile Include=`Class1.cs` />
                    </ItemGroup>
                    <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` />
                </Project>
            ");

                // ---------------------
                // Class1.cs
                // ---------------------
                ObjectModelHelpers.CreateFileInTempProjectDirectory("Class1.cs", @"
                namespace ClassLibrary16
                {
	                public class Class1
	                {
	                }
                }
            ");

                // Create a logger.
                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("foo.csproj");

                // Build the default targets using the Configuration "a;b'c".
                project.SetGlobalProperty("Configuration", EscapingUtilities.Escape("a;b'c"));
                bool success = project.Build(logger);
                Assert.True(success); // "Build failed.  See Standard Out tab for details"

                ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(@"obj\a;b'c\ClassLibrary16.dll");
                ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(@"bin\a;b'c\ClassLibrary16.dll");

                logger.AssertLogContains(String.Format("foo -> {0}", Path.Combine(ObjectModelHelpers.TempProjectDir, @"bin\a;b'c\ClassLibrary16.dll")));
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC", originalOverrideTaskHostVariable);
            }
        }
Exemple #26
0
        public void ProjectToolsVersionOverwriteIsTrue()
        {
            try
            {
                string projectContent =
                    @"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[a=$(MSBuildToolsVersion)]`/>
                        <MSBuild Projects=`p2.proj`/>
                        <MSBuild Projects=`p2.proj` ToolsVersion='3.5'/>
                        <MSBuild Projects=`p2.proj` ToolsVersion='2.0'/>
                    </Target>
                    </Project>
                    ";
                string projectContent2 =
                    @"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[b=$(MSBuildToolsVersion)]`/>
                    </Target>
                    </Project>
                    ";

                MockLogger logger = new MockLogger();
                Engine e = new Engine();
                e.RegisterLogger(logger);

                string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.proj", projectContent);
                string p2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p2.proj", projectContent2);

                Project p1 = new Project(e, "2.0");
                p1.Load(p1Path);
                p1.Build();

                logger.AssertLogContains("[a=2.0]");
                logger.AssertLogContains("[b=2.0]");

                Assertion.Assert("Cachescope should have an entry with 2.0", e.CacheManager.GetCacheScope(p1Path, new BuildPropertyGroup(), "2.0", CacheContentType.BuildResults) != null);
                Assertion.Assert("Cachescope should have an entry with 2.0", e.CacheManager.GetCacheScope(p2Path, new BuildPropertyGroup(), "2.0", CacheContentType.BuildResults) != null);
            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
        public void VerifyToolsetAndToolLocationHelperAgree()
        {
            string projectContents = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                        <UsingTask TaskName='VerifySdkPaths' TaskFactory='CodeTaskFactory' AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll' >
                         <ParameterGroup>     
                             <Sdk35ToolsPath />
                             <Sdk40ToolsPath />
                             <WindowsSDK80Path />
                          </ParameterGroup>
                            <Task>
                                <Using Namespace='Microsoft.Win32'/>
                                <Code>
                                <![CDATA[
                                    string pathTo35Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdkFile(""gacutil.exe"", TargetDotNetFrameworkVersion.Version35);
                                    if (!String.IsNullOrEmpty(pathTo35Sdk))
                                    {
                                        pathTo35Sdk = Path.GetDirectoryName(pathTo35Sdk) + ""\\"";
                                    }

                                    string pathTo40Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdkFile(""gacutil.exe"", TargetDotNetFrameworkVersion.VersionLatest); 

                                    if (!String.IsNullOrEmpty(pathTo40Sdk))
                                    {
                                        pathTo40Sdk = Path.GetDirectoryName(pathTo40Sdk) + ""\\"";
                                    }

                                    string pathTo81WinSDK = ToolLocationHelper.GetPathToWindowsSdk(TargetDotNetFrameworkVersion.VersionLatest, VisualStudioVersion.VersionLatest);" +
                                    s_verifyToolsetAndToolLocationHelperProjectCommonContent +
                                  @"if (!String.Equals(WindowsSDK80Path, pathTo81WinSDK, StringComparison.OrdinalIgnoreCase))
                                    {
                                        Log.LogError(""WindowsSDK80Path is incorrect! Registry: {0}  ToolLocationHelper: {1}"", WindowsSDK80Path, pathTo81WinSDK);
                                    }

                                    return !Log.HasLoggedErrors;
                                ]]>
                              </Code>
                            </Task>
                        </UsingTask>
                        <Target Name='Build'>
                            <VerifySdkPaths Sdk35ToolsPath='$(Sdk35ToolsPath)' Sdk40ToolsPath='$(Sdk40ToolsPath)' WindowsSDK80Path='$(WindowsSDK80Path)' />
                        </Target>
                    </Project>");

            ILogger logger = new MockLogger(_output);
            ProjectCollection collection = new ProjectCollection();
            Project p = ObjectModelHelpers.CreateInMemoryProject(collection, projectContents, logger);

            bool success = p.Build(logger);

            Assert.True(success); // "Build Failed.  See Std Out for details."
        }
Exemple #28
0
        public void ProjectBuiltUsingMSBuildTaskShouldBuildUsingDefaultToolsVersionIfOneIsNotSpecified()
        {
            try
            {
                string projectContent =
                    @"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[a=$(MSBuildToolsVersion)]`/>
                        <MSBuild Projects=`p2.proj`/>
                    </Target>
                    </Project>
                    ";
                string projectContent2 =
                    @"
                    <Project xmlns=`msbuildnamespace`>
                    <Target Name=`a`>
                        <Message Text=`[b=$(MSBuildToolsVersion)]`/>
                    </Target>
                    </Project>
                    ";

                MockLogger logger = new MockLogger();
                Engine e = new Engine();
                e.RegisterLogger(logger);

                string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.proj", projectContent);
                string p2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p2.proj", projectContent2);

                Project p1 = new Project(e);
                p1.Load(p1Path);
                p1.Build();

                logger.AssertLogContains("[a="+ ObjectModelHelpers.MSBuildDefaultToolsVersion + "]");
                Assertion.Assert("Cachescope should have an entry with 4.0", e.CacheManager.GetCacheScope(p1Path, new BuildPropertyGroup(), ObjectModelHelpers.MSBuildDefaultToolsVersion, CacheContentType.BuildResults) != null);
                Assertion.Assert("Cachescope should have an entry with default tools version", e.CacheManager.GetCacheScope(p2Path, new BuildPropertyGroup(), e.DefaultToolsVersion, CacheContentType.BuildResults) != null);

            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
        public void VerifyToolsetAndToolLocationHelperAgreeWhenVisualStudioVersionIs11()
        {
            string projectContents = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' ToolsVersion='4.0'>
                        <UsingTask TaskName='VerifySdkPaths' TaskFactory='CodeTaskFactory' AssemblyName='Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' >
                         <ParameterGroup>     
                             <Sdk35ToolsPath />
                             <Sdk40ToolsPath />
                             <WindowsSDK80Path />
                          </ParameterGroup>
                            <Task>
                                <Using Namespace='Microsoft.Win32'/>
                                <Code>
                                <![CDATA[
                                    string pathTo35Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdk(TargetDotNetFrameworkVersion.Version35, VisualStudioVersion.Version110);
                                    string pathTo40Sdk = ToolLocationHelper.GetPathToDotNetFrameworkSdk(TargetDotNetFrameworkVersion.Version40, VisualStudioVersion.Version110);
                                    string pathTo80WinSDK = ToolLocationHelper.GetPathToWindowsSdk(TargetDotNetFrameworkVersion.Version45, VisualStudioVersion.Version110);

                                    pathTo35Sdk = pathTo35Sdk == null ? pathTo35Sdk : Path.Combine(pathTo35Sdk, ""bin\\"");
                                    pathTo40Sdk = pathTo40Sdk == null ? pathTo40Sdk : Path.Combine(pathTo40Sdk, ""bin\\NetFX 4.0 Tools\\"");" +
                                    s_verifyToolsetAndToolLocationHelperProjectCommonContent +
                                   @"if (String.IsNullOrEmpty(WindowsSDK80Path))
                                    {
                                        Log.LogWarning(""WindowsSDK80Path is empty, which is technically not correct, but we're letting it slide for now because the OTG build won't have the updated registry for a while.  Make sure we don't see this warning on PURITs runs, though!"");
                                    }
                                    else if (!String.Equals(WindowsSDK80Path, pathTo80WinSDK, StringComparison.OrdinalIgnoreCase))
                                    {
                                        Log.LogError(""WindowsSDK80Path is incorrect! Registry: {0}  ToolLocationHelper: {1}"", WindowsSDK80Path, pathTo80WinSDK);
                                    }

                                    return !Log.HasLoggedErrors;
                                ]]>
                             </Code>
                            </Task>
                        </UsingTask>
                        <Target Name='Build'>
                            <VerifySdkPaths Sdk35ToolsPath='$(Sdk35ToolsPath)' Sdk40ToolsPath='$(Sdk40ToolsPath)' WindowsSDK80Path='$(WindowsSDK80Path)' />
                        </Target>
                    </Project>";

            ILogger logger = new MockLogger(_output);
            IDictionary<string, string> globalProperties = new Dictionary<string, string>();
            globalProperties.Add("VisualStudioVersion", "11.0");

            ProjectCollection collection = new ProjectCollection(globalProperties);
            Project p = ObjectModelHelpers.CreateInMemoryProject(collection, projectContents, logger, "4.0");

            bool success = p.Build(logger);

            Assert.True(success); // "Build Failed.  See Std Out for details."
        }
        public void AnyCPUWinMDObjProjectIsNot32BitPreferred()
        {
            string file = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                file = Helpers.CreateFiles("class1.cs")[0];

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>winmdobj</OutputType>
                        <Configuration>Debug</Configuration>
                      </PropertyGroup>
                      <!-- For dealing with the case where the Jupiter targets do not exist, in order to follow the appropriate codepaths in the standard managed
                           we need to be .NET 4.5 or greater -->
                      <PropertyGroup Condition=`!Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')`>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + file + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets` Condition=`Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                      <!-- Fall back to CSharp targets for the sake of this test if the Jupiter targets don't exist, since what we're testing can be equally well resolved by either -->
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` Condition=`!Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                   </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogDoesntContain(" /platform:");
            }
            finally
            {
                if (file != null)
                {
                    File.Delete(file);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
        public void VerifyGetInstalledSDKLocations3()
        {
            string testDirectoryRoot = Path.Combine(Path.GetTempPath(), "VerifyGetInstalledSDKLocations3");
            string platformDirectory = Path.Combine(testDirectoryRoot, "MyPlatform\\8.0\\");
            string sdkDirectory = Path.Combine(platformDirectory, "ExtensionSDKs\\SDkWithManifest\\2.0\\");

            string tempProjectContents = ObjectModelHelpers.CleanupFileContents(@"
             <Project DefaultTargets=""ExpandSDKReferenceAssemblies"" ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
                 <PropertyGroup>
                    <TargetPlatformIdentifier>MyPlatform</TargetPlatformIdentifier> 
                    <TargetPlatformVersion>8.0</TargetPlatformVersion>
                    <SDKRegistryRoot>SOFTWARE\Microsoft\VerifyGetInstalledSDKLocations3</SDKRegistryRoot>
                    <SDKDiskRoot>Somewhere</SDKDiskRoot>
                    <SDKLocation1>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformExtensionSDKLocation('SDkWithManifest, Version=2.0','MyPlatform','8.0', '$(SDKDirectoryRoot)','$(SDKRegistryRoot)'))</SDKLocation1>
                    <SDKLocation2>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformExtensionSDKLocation('SDkWithManifest, Version=V2.0','MyPlatform','8.0', '$(SDKDirectoryRoot)','$(SDKRegistryRoot)'))</SDKLocation2>                 
                    <SDKLocation3>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('MyPlatform','8.0', '$(SDKDirectoryRoot)','$(SDKRegistryRoot)'))</SDKLocation3> 
                    <SDKName>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName('MyPlatform','8.0', '$(SDKDirectoryRoot)', '$(SDKRegistryRoot)'))</SDKName>
                 </PropertyGroup>
                 <Import Project=""$(MSBuildBinPath)\Microsoft.Common.targets""/>
              </Project>");

            string platformSDKManifestContents = @"<FileList
                    DisplayName = ""MyPlatform from the registry""
                    PlatformIdentity = ""MyPlatform, version=8.0""
                    TargetFramework = "".NETCore, version=v4.5; .NETFramework, version=v4.5""
                    MinVSVersion = ""12.0""
                    MinOSVersion = ""6.2.1""
                    MaxOSVersionTested = ""6.2.1""
                    UnsupportedDowntarget = ""MyPlatform, version=8.0"">

                <File Reference = ""Windows"">
	                <ToolboxItems VSCategory = ""Toolbox.Default""/>
                </File>
            </FileList>";

            string registryKey = @"SOFTWARE\Microsoft\VerifyGetInstalledSDKLocations3\";
            RegistryKey baseKey = Registry.CurrentUser;

            try
            {
                RegistryKey folderKey = baseKey.CreateSubKey(registryKey + @"\MyPlatform\v8.0\ExtensionSDKS\SDKWithManifest\2.0");
                folderKey.SetValue("", Path.Combine(testDirectoryRoot, sdkDirectory));

                folderKey = baseKey.CreateSubKey(registryKey + @"\MyPlatform\v8.0");
                folderKey.SetValue("", Path.Combine(testDirectoryRoot, platformDirectory));


                if (Directory.Exists(testDirectoryRoot))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDirectoryRoot, true);
                }

                Directory.CreateDirectory(testDirectoryRoot);
                Directory.CreateDirectory(sdkDirectory);
                File.WriteAllText(Path.Combine(sdkDirectory, "sdkManifest.xml"), "HI");
                File.WriteAllText(Path.Combine(platformDirectory, "sdkManifest.xml"), platformSDKManifestContents);

                string testProjectFile = Path.Combine(testDirectoryRoot, "testproject.csproj");

                File.WriteAllText(testProjectFile, tempProjectContents);

                MockLogger logger = new MockLogger(_output);

                ProjectCollection pc = new ProjectCollection();
                Project project = pc.LoadProject(testProjectFile);
                string propertyValue1 = project.GetPropertyValue("SDKLocation1");
                string propertyValue2 = project.GetPropertyValue("SDKLocation2");
                string propertyValue3 = project.GetPropertyValue("SDKLocation3");
                string sdkName = project.GetPropertyValue("SDKName");

                Assert.True(propertyValue1.Equals(sdkDirectory, StringComparison.OrdinalIgnoreCase));
                Assert.True(propertyValue3.Equals(platformDirectory, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(0, propertyValue2.Length);
                Assert.Equal("MyPlatform from the registry", sdkName);
            }
            finally
            {
                try
                {
                    baseKey.DeleteSubKeyTree(registryKey);
                }
                catch (Exception)
                {
                }
                if (Directory.Exists(testDirectoryRoot))
                {
                    FileUtilities.DeleteDirectoryNoThrow(testDirectoryRoot, true);
                }
            }
        }
        private bool BuildProject(IDictionary <string, string> globalProperties, string toolsVersion, out MockLogger logger)
        {
            logger = new MockLogger();

            using (ProjectCollection projectCollection = new ProjectCollection())
            {
                Project project = new Project(ProjectFile, globalProperties, toolsVersion, projectCollection);

                return(project.Build(logger));
            }
        }