public void DoesNotImportDirectoryBuildProjectIfNotExist() { // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); Assert.Equal("true", project.GetPropertyValue(ImportDirectoryBuildProjectPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue(DirectoryBuildProjectBasePathPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(DirectoryBuildProjectFile, project.GetPropertyValue(DirectoryBuildProjectFilePropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue(DirectoryBuildProjectPathPropertyName)); }
protected DirectoryBuildProjectImportTestBase() { ObjectModelHelpers.DeleteTempProjectDirectory(); }
public void Dispose() { ObjectModelHelpers.DeleteTempProjectDirectory(); }
public void DoesNotImportDirectoryBuildProjectWhenDisabled() { // --------------------- // Directory.Build.props // --------------------- ObjectModelHelpers.CreateFileInTempProjectDirectory(DirectoryBuildProjectFile, BasicDirectoryBuildProjectContents); // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, $@" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion`> <PropertyGroup> <{ImportDirectoryBuildProjectPropertyName}>false</{ImportDirectoryBuildProjectPropertyName}> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); Assert.Equal("false", project.GetPropertyValue(ImportDirectoryBuildProjectPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue("WasDirectoryBuildProjectImported"), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue(DirectoryBuildProjectBasePathPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue(DirectoryBuildProjectFilePropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(String.Empty, project.GetPropertyValue(DirectoryBuildProjectPathPropertyName)); }
public void ImportsDirectoryBuildProjectIfExists() { ObjectModelHelpers.CreateFileInTempProjectDirectory(DirectoryBuildProjectFile, BasicDirectoryBuildProjectContents); // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); Assert.Equal("true", project.GetPropertyValue(ImportDirectoryBuildProjectPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal("true", project.GetPropertyValue("WasDirectoryBuildProjectImported"), StringComparer.OrdinalIgnoreCase); Assert.Equal(ObjectModelHelpers.TempProjectDir, project.GetPropertyValue(DirectoryBuildProjectBasePathPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(DirectoryBuildProjectFile, project.GetPropertyValue(DirectoryBuildProjectFilePropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal(Path.Combine(ObjectModelHelpers.TempProjectDir, DirectoryBuildProjectFile), project.GetPropertyValue(DirectoryBuildProjectPathPropertyName)); }
public void SetGetHostObjectInProject() { string projectContents = @" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name=`Build` > <MakeDir Directories=`c:\rajeev` /> <Csc Sources=`foo.cs` /> </Target> </Project> "; Project project = ObjectModelHelpers.CreateInMemoryProject(projectContents); MyHostObject hostObject1 = new MyHostObject(); MyHostObject hostObject2 = new MyHostObject(); // Set hostObject1 to the "MakeDir" task, and set hostObject2 to the "Csc" task. foreach (Target target in project.Targets) { foreach (BuildTask myTask in target) { if (myTask.Name == "MakeDir") { myTask.HostObject = hostObject1; } else if (myTask.Name == "Csc") { myTask.HostObject = hostObject2; } else { Assertion.Assert("Unknown task", false); } } } bool foundMakeDir = false; bool foundCsc = false; // Now retrieve the host objects for "MakeDir" and "Csc", and confirm they're the // same ones we set originally. foreach (Target target in project.Targets) { foreach (BuildTask myTask in target) { if (myTask.Name == "MakeDir") { Assertion.AssertSame(myTask.HostObject, hostObject1); Assertion.Assert(myTask.HostObject != hostObject2); foundMakeDir = true; } else if (myTask.Name == "Csc") { Assertion.AssertSame(myTask.HostObject, hostObject2); Assertion.Assert(myTask.HostObject != hostObject1); foundCsc = true; } else { Assertion.Assert("Unknown task", false); } } } Assertion.Assert(foundMakeDir && foundCsc); }
public void IncludeAndExcludeUnescaping() { string tempFolder = Path.Combine(Path.GetTempPath(), "IncludeAndExcludeUnescaping"); string matchesFoo = Path.Combine(tempFolder, "*"); string foo = Path.Combine(tempFolder, "foo"); StreamWriter sw = null; try { Directory.CreateDirectory(tempFolder); sw = File.CreateText(foo); string projectContents = String.Format(@" <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`> <ItemGroup> <i1 Include=`)` Exclude=`)`/> <i2 Include=`%29` Exclude=`%29`/> <i3 Include=`%29` Exclude=`)`/> <i4 Include=`)` Exclude=`%29`/> <i5 Include=`);x` Exclude=`%29`/> <i6 Include=`x` Exclude=`y`/> <i7 Include=` ` Exclude=`y`/> <i8 Include=`x` Exclude=``/> <i9 Include=`);%29` Exclude=`)`/> <i10 Include=`%2a` Exclude=`%2a`/> <i11 Include=`{0}` Exclude=`{1}`/> <i12 Include=`{1}` Exclude=`{1}`/> </ItemGroup> </Project> ", foo, matchesFoo); Project project = ObjectModelHelpers.CreateInMemoryProject(projectContents); BuildItemGroup i1Items = project.GetEvaluatedItemsByName("i1"); BuildItemGroup i2Items = project.GetEvaluatedItemsByName("i2"); BuildItemGroup i3Items = project.GetEvaluatedItemsByName("i3"); BuildItemGroup i4Items = project.GetEvaluatedItemsByName("i4"); BuildItemGroup i5Items = project.GetEvaluatedItemsByName("i5"); BuildItemGroup i6Items = project.GetEvaluatedItemsByName("i6"); BuildItemGroup i7Items = project.GetEvaluatedItemsByName("i7"); BuildItemGroup i8Items = project.GetEvaluatedItemsByName("i8"); BuildItemGroup i9Items = project.GetEvaluatedItemsByName("i9"); BuildItemGroup i10Items = project.GetEvaluatedItemsByName("i10"); BuildItemGroup i11Items = project.GetEvaluatedItemsByName("i11"); BuildItemGroup i12Items = project.GetEvaluatedItemsByName("i12"); Assertion.Assert(") should exclude )", i1Items.Count == 0); Assertion.Assert("%29 should exclude %29", i2Items.Count == 0); Assertion.Assert(") should exclude %29", i3Items.Count == 0); Assertion.Assert("%29 should exclude )", i4Items.Count == 0); Assertion.Assert("%29 should exclude ) from );x", i5Items.Count == 1 && i5Items[0].FinalItemSpecEscaped == "x"); Assertion.Assert("y should not exclude x", i6Items.Count == 1 && i6Items[0].FinalItemSpecEscaped == "x"); Assertion.Assert("empty include, y exclude", i7Items.Count == 0); Assertion.Assert("x include, empty exclude", i8Items.Count == 1 && i8Items[0].FinalItemSpecEscaped == "x"); Assertion.Assert(") should exclude both from );%29", i9Items.Count == 0); Assertion.Assert("%2a should exclude %2a", i10Items.Count == 0); Assertion.Assert("* matching foo should exclude foo", i11Items.Count == 0); Assertion.Assert("* should exclude *", i12Items.Count == 0); } finally { if (null != sw) { sw.Close(); } File.Delete(foo); Directory.Delete(tempFolder); } }
public void DoesNotImportProjectIfNotExist() { // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); string projectExtensionsPath = project.GetPropertyValue("MSBuildProjectExtensionsPath"); projectExtensionsPath.ShouldNotBeNullOrWhiteSpace(); Directory.Exists(projectExtensionsPath).ShouldBeFalse(); project.GetPropertyValue(PropertyNameToEnableImport).ShouldBe("true"); project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBeEmpty(); }
public void DoesNotImportProjectWhenDisabled() { // --------------------- // Directory.Build.props // --------------------- ObjectModelHelpers.CreateFileInTempProjectDirectory(ImportProjectPath, BasicProjectImportContents); // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, $@" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <PropertyGroup> <{PropertyNameToEnableImport}>false</{PropertyNameToEnableImport}> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); string projectExtensionsDirectory = Path.Combine(ObjectModelHelpers.TempProjectDir, Path.GetDirectoryName(ImportProjectPath)); project.GetPropertyValue(PropertyNameToEnableImport).ShouldBe("false"); project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBeEmpty(); Directory.Exists(projectExtensionsDirectory).ShouldBeTrue(); project.GetPropertyValue("MSBuildProjectExtensionsPath").ShouldBe($@"{projectExtensionsDirectory}{Path.DirectorySeparatorChar}"); }
public void WarningIfBaseIntermediateOutputPathIsChangedInBodyOfProject() { Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <PropertyGroup> <EnableBaseIntermediateOutputPathMismatchWarning>true</EnableBaseIntermediateOutputPathMismatchWarning> <BaseIntermediateOutputPath>foo</BaseIntermediateOutputPath> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); MockLogger logger = new MockLogger(); project.Build("_CheckForInvalidConfigurationAndPlatform", new[] { logger }).ShouldBeTrue(); logger.Warnings.Select(i => i.Code).FirstOrDefault().ShouldBe("MSB3539"); }
public void ErrorIfChangedInBodyOfProject() { Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <PropertyGroup> <MSBuildProjectExtensionsPath>foo</MSBuildProjectExtensionsPath> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); MockLogger logger = new MockLogger(); project.Build("_CheckForInvalidConfigurationAndPlatform", new[] { logger }).ShouldBeFalse(); logger.Errors.Select(i => i.Code).FirstOrDefault().ShouldBe("MSB3540"); }
protected ProjectExtensionsImportTestBase() { ObjectModelHelpers.DeleteTempProjectDirectory(); }
public void ImportsProjectIfExists() { ObjectModelHelpers.CreateFileInTempProjectDirectory(ImportProjectPath, BasicProjectImportContents); // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, @" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); project.GetPropertyValue(PropertyNameToEnableImport).ShouldBe("true"); project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBe("true"); }
public void ImportsDirectoryBuildProjectCustomFile() { string customFilePath = ObjectModelHelpers.CreateFileInTempProjectDirectory(CustomBuildProjectFile, BasicDirectoryBuildProjectContents); // --------------------- // src\Foo\Foo.csproj // --------------------- Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, $@" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <PropertyGroup> <{DirectoryBuildProjectPathPropertyName}>{customFilePath}</{DirectoryBuildProjectPathPropertyName}> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> </Project> ")); Assert.Equal("true", project.GetPropertyValue(ImportDirectoryBuildProjectPropertyName), StringComparer.OrdinalIgnoreCase); Assert.Equal("true", project.GetPropertyValue("WasDirectoryBuildProjectImported"), StringComparer.OrdinalIgnoreCase); Assert.Equal(customFilePath, project.GetPropertyValue(DirectoryBuildProjectPathPropertyName)); Assert.Contains(customFilePath, project.GetPropertyValue("MSBuildAllProjects")); }