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 DoesNotImportDirectoryBuildProjectIfNotExist() { // --------------------- // 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> ")); 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)); }
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 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"); }
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 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 ImportNuGetPropsWhenDoesNotExists() { var projectRelativePath = Path.Combine("src", "foo1", "foo1.csproj"); var nugetPropsRelativePath = Path.Combine(Path.GetDirectoryName(projectRelativePath), NuGetPropsProjectFile); // --------------------- // src\Foo\Foo.csproj // --------------------- ObjectModelHelpers.CreateFileInTempProjectDirectory(projectRelativePath, $@" <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`http://schemas.microsoft.com/developer/msbuild/2003`> <PropertyGroup> <{NuGetPropsPropertyName}>{nugetPropsRelativePath}</{NuGetPropsPropertyName}> </PropertyGroup> <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> </Project> "); Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(projectRelativePath); Assert.Empty(project.GetPropertyValue("NuGetPropsIsImported")); }
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)); }