public void RecursiveDirOutOfProc() { using var env = TestEnvironment.Create(_testOutput); ObjectModelHelpers.DeleteTempProjectDirectory(); string projectFileFullPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("Myapp.proj", @" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name =`Repro` Returns=`@(Text)`> <CreateItem Include=`**\*.txt`> <Output TaskParameter=`Include` ItemName=`Text`/> </CreateItem> </Target> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory(Path.Combine("Subdir", "Bar.txt"), "bar"); env.SetEnvironmentVariable("MSBUILDTARGETRESULTCOMPRESSIONTHRESHOLD", "0"); BuildRequestData data = new BuildRequestData(projectFileFullPath, new Dictionary <string, string>(), null, new string[] { "Repro" }, null); BuildParameters parameters = new BuildParameters { DisableInProcNode = true, EnableNodeReuse = false, Loggers = new ILogger[] { new MockLogger(_testOutput) }, }; BuildResult result = BuildManager.DefaultBuildManager.Build(parameters, data); result.OverallResult.ShouldBe(BuildResultCode.Success); result.ResultsByTarget["Repro"].Items[0].GetMetadata("RecursiveDir").ShouldBe("Subdir" + Path.DirectorySeparatorChar); }
public void AbsolutePath() { string fileName = ObjectModelHelpers.CreateFileInTempProjectDirectory("file.temp", "foo"); FileInfo testFile = new FileInfo(fileName); ConvertToAbsolutePath t = new ConvertToAbsolutePath(); t.BuildEngine = new MockEngine(); string currentDirectory = Directory.GetCurrentDirectory(); try { Directory.SetCurrentDirectory(ObjectModelHelpers.TempProjectDir); t.Paths = new ITaskItem[] { new TaskItem(fileName) }; Assert.True(t.Execute()); // "success" } finally { Directory.SetCurrentDirectory(currentDirectory); } Assert.Single(t.AbsolutePaths); Assert.Equal(testFile.FullName, t.AbsolutePaths[0].ItemSpec); ObjectModelHelpers.DeleteTempProjectDirectory(); }
public void TestICollectionMethods() { ObjectModelHelpers.DeleteTempProjectDirectory(); ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.proj", @" <Project xmlns=`msbuildnamespace`> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.proj", @" <Project xmlns=`msbuildnamespace`> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", @" <Project xmlns=`msbuildnamespace`> <Import Project=`import1.proj` /> <Import Project=`import2.proj` /> <Target Name=`Build`> <WashCar/> </Target> </Project> "); Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main.proj", null); string import1Path = Path.Combine(ObjectModelHelpers.TempProjectDir, "import1.proj"); string import2Path = Path.Combine(ObjectModelHelpers.TempProjectDir, "import2.proj"); ImportCollection imports = project.Imports; Assertion.AssertEquals(2, imports.Count); Import[] array = new Import[2]; imports.CopyTo(array, 0); Dictionary <string, Import> hash = new Dictionary <string, Import>(StringComparer.OrdinalIgnoreCase); hash[array[0].EvaluatedProjectPath] = array[0]; hash[array[1].EvaluatedProjectPath] = array[1]; Assertion.AssertEquals(imports[import1Path], hash[import1Path]); Assertion.AssertEquals(imports[import2Path], hash[import2Path]); object[] arrayObjects = new object[2]; imports.CopyTo(arrayObjects, 0); hash.Clear(); hash[((Import)arrayObjects[0]).EvaluatedProjectPath] = ((Import)arrayObjects[0]); hash[((Import)arrayObjects[1]).EvaluatedProjectPath] = ((Import)arrayObjects[1]); Assertion.AssertEquals(imports[import1Path], hash[import1Path]); Assertion.AssertEquals(imports[import2Path], hash[import2Path]); Assertion.AssertEquals("import1.proj", imports[import1Path].ProjectPath); Assertion.AssertEquals("import2.proj", imports[import2Path].ProjectPath); }
public void WildcardsWithRecursiveDir() { ObjectModelHelpers.DeleteTempProjectDirectory(); ObjectModelHelpers.CreateFileInTempProjectDirectory("Myapp.proj", @" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name =`Repro`> <CreateItem Include=`**\*.txt`> <Output TaskParameter=`Include` ItemName=`Text`/> </CreateItem> <Copy SourceFiles=`@(Text)` DestinationFiles=`Destination\%(RecursiveDir)%(Filename)%(Extension)`/> </Target> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("Foo.txt", "foo"); ObjectModelHelpers.CreateFileInTempProjectDirectory(Path.Combine("Subdir", "Bar.txt"), "bar"); MockLogger logger = new MockLogger(_testOutput); ObjectModelHelpers.BuildTempProjectFileExpectSuccess("Myapp.proj", logger); ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(Path.Combine("Destination", "Foo.txt")); ObjectModelHelpers.AssertFileExistsInTempProjectDirectory(Path.Combine("Destination", "Subdir", "Bar.txt")); }
public void RemoveExistingImport() { ObjectModelHelpers.DeleteTempProjectDirectory(); ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.proj", @" <Project xmlns=`msbuildnamespace`> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.proj", @" <Project xmlns=`msbuildnamespace`> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", @" <Project xmlns=`msbuildnamespace`> <Import Project=`import1.proj` /> <Import Project=`import2.proj` /> <Target Name=`Build`> <WashCar/> </Target> </Project> "); Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main.proj", null); ImportCollection imports = project.Imports; Assertion.AssertEquals(2, imports.Count); imports.RemoveImport(imports[Path.Combine(ObjectModelHelpers.TempProjectDir, "import1.proj")]); // First validate that the ImportCollection only contains a single Import Assertion.AssertEquals(1, imports.Count); // Now validate that the ImportCollection properly updated its parent Project (by inspecting the // project's in-memory Xml) int importCount = 0; foreach (XmlNode childNode in project.ProjectElement) { if (childNode.Name == XMakeElements.import) { importCount++; } } Assertion.AssertEquals(1, importCount); }
public void AttemptToRemoveImportFromAnotherProjectShouldThrowException() { ObjectModelHelpers.DeleteTempProjectDirectory(); ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.proj", @" <Project xmlns=`msbuildnamespace`> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("main1.proj", @" <Project xmlns=`msbuildnamespace`> <Import Project=`import1.proj` /> <Target Name=`Build`> <WashCar/> </Target> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("main2.proj", @" <Project xmlns=`msbuildnamespace`> <Import Project=`import1.proj` /> <Target Name=`Build`> <WashCar/> </Target> </Project> "); Project project1 = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main1.proj", null); Project project2 = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main2.proj", null); ImportCollection imports1 = project1.Imports; ImportCollection imports2 = project2.Imports; // Should throw an InvalidOperationException imports1.RemoveImport(imports2[Path.Combine(ObjectModelHelpers.TempProjectDir, "import1.proj")]); }
public void ToolsVersionRespectedWhenBuildingASolution() { ObjectModelHelpers.DeleteTempProjectDirectory(); Engine engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath)); // We've intentionally assigned the correct BinPath value to the tools version '3.5' since later // we will request the engine build the solution with that tools version, and the engine will // need to locate the default tasks. If the override we're going to specify isn't in fact applied, // the engine will try to load the tasks from the bogus toolpath, and that will fail the solution build, // so this test will fail. engine.AddToolset(new Toolset("3.5", engine.BinPath)); engine.AddToolset(new Toolset("2.0", "anotherToolsPath")); string solutionFileContents = @" Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|AnyCPU = Debug|AnyCPU Release|AnyCPU = Release|AnyCPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal "; string solutionFullPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("ConsoleApplication1.sln", solutionFileContents); // The parent project doesn't declare its ToolsVersion, and its ToolsVersion is not overridden string parentProjectContent = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; Project parentProject = ObjectModelHelpers.CreateInMemoryProject(engine, parentProjectContent, null); EngineProxy engineProxy = CreateEngineProxyWithDummyTaskEngine(engine, parentProject); bool success = engineProxy.BuildProjectFile (solutionFullPath, null, null, null, "3.5"); Assertion.Assert("Expected a successful build!", success); }
public void ItemsPickUpItemDefinitionMetadataFromImportedProject() { try { ObjectModelHelpers.CreateFileInTempProjectDirectory("foo.proj", @" <Project DefaultTargets=`t` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <ItemGroup> <ItemWithDefinition Include=`foo.cs` /> </ItemGroup> <Target Name=`t`> <Message Text=`[%(ItemWithDefinition.SomeMetadata)]` /> </Target> <Import Project=`foo2.proj` /> </Project> "); ObjectModelHelpers.CreateFileInTempProjectDirectory("foo2.proj", @" <Project DefaultTargets=`t2` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <ItemDefinitionGroup> <ItemWithDefinition> <SomeMetadata>foo</SomeMetadata> </ItemWithDefinition> </ItemDefinitionGroup> <Target Name=`t2` /> </Project> "); MockLogger logger = ObjectModelHelpers.BuildTempProjectFileExpectSuccess("foo.proj"); logger.AssertLogContains("[foo]"); } finally { ObjectModelHelpers.DeleteTempProjectDirectory(); } }
public void Dispose() { ObjectModelHelpers.DeleteTempProjectDirectory(); }
protected DirectoryBuildProjectImportTestBase() { ObjectModelHelpers.DeleteTempProjectDirectory(); }
protected ProjectExtensionsImportTestBase() { ObjectModelHelpers.DeleteTempProjectDirectory(); }