Esempio n. 1
0
        public void AddItemGroup()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup Label=""test label"" Condition=""test Condition"" />
</Project>";

            ProjectBuilder.Create()
            .AddItemGroup("test Condition", "test label")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup />
  <ItemGroup Label=""test label"" Condition=""test Condition"" />
  <ItemGroup Condition=""New Condition"" />
</Project>";
            ProjectBuilder.Create()
            .AddItemGroup()
            .AddItemGroup("test Condition", "test label")
            .AddItemGroup("New Condition")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
        public void InvalidProjectsLogGoodInfo()
        {
            var projectA = ProjectBuilder
                           .Create()
                           .AddImport(new Import(@"$(Foo)\foo.props"))
                           .Save(GetTempFileName());

            var dirsProj = ProjectBuilder
                           .Create()
                           .AddProperty("IsTraversal=true")
                           .AddItem($"ProjectFile={projectA.FullPath}")
                           .Save(GetTempFileName());

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log);

            loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            var errorEventArgs = _buildEngine.Errors.ShouldHaveSingleItem();

            errorEventArgs.Code.ShouldBe("MSB4019");
            errorEventArgs.ColumnNumber.ShouldBe(3);
            errorEventArgs.HelpKeyword.ShouldBe("MSBuild.ImportedProjectNotFound");
            errorEventArgs.LineNumber.ShouldBe(3);
            errorEventArgs.File.ShouldBe(projectA.FullPath);
        }
Esempio n. 3
0
        public void AddImport()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <Import Project=""build.props"" />
</Project>";

            ProjectBuilder.Create()
            .AddImport("build.props")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <Import Project=""build.props"" Condition=""Condition"" Label=""Label"" />
  <Import Project=""build2.props"" Condition=""Condition2"" Label=""Label2"" />
  <ItemGroup />
  <PropertyGroup />
  <Import Project=""test.props"" />
</Project>";
            ProjectBuilder.Create()
            .AddImport(new[] { new Import("build.props", "Condition", "Label") })
            .AddImport(new[] { new Import("build2.props", "Condition2", "Label2") })
            .AddItemGroup()
            .AddPropertyGroup()
            .AddImport("test.props")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
Esempio n. 4
0
 private void CreateAggregateImportProject(string project)
 {
     Directory.CreateDirectory(Path.GetDirectoryName(project));
     ProjectBuilder.Create()
     .AddProperty("CBTAggregatePackage=NuGetPath_Microsoft_Build=src1|src2")
     .Save(project);
 }
Esempio n. 5
0
        public void Save()
        {
            string tmpFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), "test.proj");

            ProjectBuilder.Create("14.0", "TestDefaultTarget", "TestInitialTarget", "TestLabel")
            .Save(tmpFile);
            File.Exists(tmpFile).ShouldBe(true);
            File.Delete(tmpFile);
        }
Esempio n. 6
0
        /// <summary>
        /// Build from command line
        /// </summary>
        /// <param name="projectFile"></param>
        /// <param name="options"></param>
        public static void Build(string projectFile, FDBuildOptions options)
        {
            Project project = ProjectLoader.Load(projectFile);

            project.TraceEnabled = !options.NoTrace;
            options.Language     = project.Language.ToUpper();
            ProjectBuilder builder = ProjectBuilder.Create(project, options.IpcName, options.CompilerPath);

            builder.Build(options.ExtraClasspaths, options.NoTrace, options.NoPreBuild, options.NoPostBuild);
        }
Esempio n. 7
0
        /// <summary>
        /// Build from pre/post command: FDBuild
        /// </summary>
        /// <param name="projectFile"></param>
        public static void BuildProject(string projectFile)
        {
            Project project = ProjectLoader.Load(projectFile);

            Program.BuildOptions.Language = project.Language.ToUpper();

            ProjectBuilder builder = ProjectBuilder.Create(project, Program.BuildOptions.IpcName, Program.BuildOptions.CompilerPath);

            builder.BuildCommand(Program.BuildOptions.ExtraClasspaths, Program.BuildOptions.NoTrace);
        }
Esempio n. 8
0
        public void AddTarget()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <PropertyGroup Label=""test label"" Condition=""test Condition"" />
  <Target Name=""foo"">
    <PropertyGroup>
      <fun>bar</fun>
    </PropertyGroup>
    <ItemGroup>
      <testing Include=""cows"" />
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <outOfTarget>hello</outOfTarget>
  </PropertyGroup>
</Project>";

            ProjectBuilder.Create()
            .AddPropertyGroup("test Condition", "test label")
            .AddTarget("foo")
            .AddProperty("fun=bar")
            .AddItem("testing=cows")
            .ExitTarget()
            .AddProperty("outOfTarget=hello")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <Target Name=""foo"" AfterTargets=""after"" BeforeTargets=""before"" DependsOnTargets=""dep"" Inputs=""inp"" Outputs=""out"" Label=""lab"" Condition=""con"" />
  <PropertyGroup>
    <test>here</test>
  </PropertyGroup>
  <Target Name=""cow"" />
  <Target Name=""bar"">
    <PropertyGroup>
      <intarget>here</intarget>
    </PropertyGroup>
  </Target>
</Project>";
            ProjectBuilder.Create()
            .AddTarget("foo", "con", "lab", "after", "before", "dep", "inp", "out", false)
            .ExitTarget()
            .AddProperty("test=here")
            .AddTarget("cow")
            .AddTarget("bar")
            .AddProperty("intarget=here")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
Esempio n. 9
0
        public void AddMetadata()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup>
    <TestItem Include=""IncludeValue"">
      <TestMName>MValue</TestMName>
      <M2Name>M2Value</M2Name>
      <M3Name Condition=""test condition"" Label=""test label"">
      </M3Name>
      <M4Name>
      </M4Name>
    </TestItem>
    <name Include=""value"">
      <foo>bar</foo>
      <bar>baz</bar>
      <met Condition=""con"" Label=""lab"">cow</met>
      <TestMName>MValue</TestMName>
      <M2Name>M2Value</M2Name>
      <M3Name Condition=""test condition"" Label=""test label"">
      </M3Name>
      <M4Name>
      </M4Name>
    </name>
    <foo Include=""bar"">
      <TestMName>MValue</TestMName>
      <M2Name>M2Value</M2Name>
      <M3Name Condition=""test condition"" Label=""test label"">
      </M3Name>
      <M4Name>
      </M4Name>
    </foo>
  </ItemGroup>
</Project>";

            ProjectBuilder.Create()
            .AddItem(
                "TestItem=IncludeValue",
                new Item("name", "value", metadata: new ItemMetadata[] { "foo=bar", "bar=baz", new ItemMetadata("met", "cow", "con", "lab") }),
                "foo=bar"
                )
            .WithItemMetadata("TestMName=MValue")
            .WithItemMetadata(
                new ItemMetadata("M2Name", "M2Value"),
                new ItemMetadata("M3Name", null, "test condition", "test label"),
                new ItemMetadata("M4Name", string.Empty)
                )
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
Esempio n. 10
0
 private void CreateTestProject(string testProject)
 {
     Directory.CreateDirectory(Path.GetDirectoryName(testProject));
     ProjectBuilder.Create()
     .AddProperty("CBTEnablePackageRestore=true")
     .AddProperty("Platform=AnyCPU", "Configuration=Debug", "OutputPath=bin")
     .AddProperty($"CBTNuGetTasksAssemblyPath={Assembly.GetExecutingAssembly().Location}")
     .AddProperty($"CBTNuGetTasksAssemblyName=$(CBTNuGetTasksAssemblyPath.GetType().Assembly.GetType(\'System.AppDomain\').GetProperty(\'CurrentDomain\').GetValue(null).SetData(\'CBT_NUGET_ASSEMBLY_PATH\', $(CBTNuGetTasksAssemblyPath)))$(CBTNuGetTasksAssemblyPath.GetType().Assembly.GetType(\'System.AppDomain\').GetProperty(\'CurrentDomain\').GetValue(null).SetData(\'CBT_NUGET_ASSEMBLY\', $(CBTNuGetTasksAssemblyPath.GetType().Assembly.GetType(\'System.AppDomain\').GetProperty(\'CurrentDomain\').GetValue(null).Load($(CBTNuGetTasksAssemblyPath.GetType().Assembly.GetType(\'System.IO.File\').GetMethod(\'ReadAllBytes\').Invoke(null, $([System.IO.Directory]::GetFiles($([System.IO.Path]::GetDirectoryName($(CBTNuGetTasksAssemblyPath))), $([System.IO.Path]::GetFileName($(CBTNuGetTasksAssemblyPath)))))))))))$(CBTNuGetTasksAssemblyPath.GetType().Assembly.GetType(\'System.AppDomain\').GetProperty(\'CurrentDomain\').GetValue(null).GetData(\'CBT_NUGET_ASSEMBLY\'))")
     .AddProperty("CBTAggregatePackage=NuGetPath_Microsoft_Build=src1|scr2")
     .AddProperty($"CBTNuGetIntermediateOutputPath={_destPackagesPath}")
     .AddProperty($@"IntermediateOutputPath={_enlistmentRoot}\obj\$(Configuration)\$(Platform)\AggregatePackage.proj")
     .AddImport($@"{_installedNupkgs["CBT.NuGet.AggregatePackage"]}\build\After.CBT.NuGet.props")
     .AddImport($@"{_installedNupkgs["CBT.NuGet.AggregatePackage"]}\build\After.Microsoft.Common.targets")
     .AddTarget("Build")
     .Save(testProject);
 }
        public void ProjectReferencesWork()
        {
            var projectB = ProjectBuilder.Create()
                           .Save(GetTempFileName());

            var projectA = ProjectBuilder
                           .Create()
                           .AddProjectReference(projectB)
                           .Save(GetTempFileName());

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath });

            projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { projectA.FullPath, projectB.FullPath });
        }
Esempio n. 12
0
        public void WritePropsAggregatePackageTest()
        {
            string propsFile                  = Path.Combine(TestRootPath, "props", "foo.props");
            string propsFileExpect            = Path.Combine(TestRootPath, "props", "fooExpected.props");
            Dictionary <string, string> props = new Dictionary <string, string>();

            props.Add("foo", "Myvalue");
            props.Add("foo2", "MyValue");
            var aggPkgs = new AggregatePackages();

            aggPkgs.CreatePropsFile(props, propsFile);
            var propsContents = File.ReadAllText(propsFile);
            var root          = ProjectBuilder.Create()
                                .AddProperty("MSBuildAllProjects=$(MSBuildAllProjects);$(MSBuildThisFileFullPath)", "foo=Myvalue", "foo2=MyValue")
                                .Save(propsFileExpect);

            propsContents.ShouldBe(File.ReadAllText(propsFileExpect));
        }
        public void GlobalPropertiesSetCorrectly()
        {
            Dictionary <string, string> expectedGlobalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Property1", "1A836FEB3ABA43B183034DFDD5C4E375" },
                { "Property2", "CEEC5C9FF0F344DAA32A0F545460EB2C" }
            };

            var projectA = ProjectBuilder
                           .Create()
                           .Save(GetTempFileName());

            MSBuildProjectLoader loader = new MSBuildProjectLoader(expectedGlobalProperties, MSBuildToolsVersion, Log);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath });

            projectCollection.GlobalProperties.ShouldBe(expectedGlobalProperties);
        }
Esempio n. 14
0
        public void Create()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
</Project>";

            ProjectBuilder.Create()
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""14.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""TestDefaultTarget"" InitialTargets=""TestInitialTarget"" Label=""TestLabel"">
</Project>";
            ProjectBuilder.Create("14.0", "TestDefaultTarget", "TestInitialTarget", "TestLabel")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
Esempio n. 15
0
        public void AddItem()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup Label=""groupLabel"">
    <item1 Include=""value1"" Label=""my item label"" Condition=""my item condition"" />
    <item2 Include=""value2"" Label=""my item label"" Condition=""my item condition"" />
  </ItemGroup>
</Project>";

            ProjectBuilder.Create()
            .AddItemGroup(label: "groupLabel")
            .AddItem(
                new Item("item1", "value1", "my item condition", "my item label"),
                new Item("item2", "value2", "my item condition", "my item label")
                )
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <ItemGroup>
    <item1 Include=""value1"" Label=""my item label"" Condition=""my item condition"" />
    <item2 Include=""value2"" Label=""my item label"" Condition=""my item condition"" />
  </ItemGroup>
  <ItemGroup>
    <Name Include=""Value"" />
  </ItemGroup>
</Project>";
            ProjectBuilder.Create()
            .AddItem(
                new Item("item1", "value1", "my item condition", "my item label"),
                new Item("item2", "value2", "my item condition", "my item label")
                )
            .AddItemGroup()
            .AddItem("Name=Value")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
Esempio n. 16
0
        public void AddProperty()
        {
            string expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <PropertyGroup Label=""groupLabel"">
    <item1 Label=""my item label"" Condition=""my item condition"">value1</item1>
    <item2 Label=""my item label"" Condition=""my item condition"">value2</item2>
  </PropertyGroup>
</Project>";

            ProjectBuilder.Create()
            .AddPropertyGroup(label: "groupLabel")
            .AddProperty(
                new Property("item1", "value1", "my item condition", "my item label"),
                new Property("item2", "value2", "my item condition", "my item label")
                )
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);

            expectedOutput =
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <PropertyGroup>
    <item1 Label=""my item label"" Condition=""my item condition"">value1</item1>
    <item2 Label=""my item label"" Condition=""my item condition"">value2</item2>
  </PropertyGroup>
  <PropertyGroup>
    <Name>Value</Name>
  </PropertyGroup>
</Project>";
            ProjectBuilder.Create()
            .AddProperty(
                new Property("item1", "value1", "my item condition", "my item label"),
                new Property("item2", "value2", "my item condition", "my item label")
                )
            .AddPropertyGroup()
            .AddProperty("Name=Value")
            .ProjectRoot
            .RawXmlShouldBe(expectedOutput);
        }
        public void BuildFailsIfError()
        {
            var dirsProj = ProjectBuilder
                           .Create()
                           .AddProperty("IsTraversal=true")
                           .AddItem("ProjectFile=does not exist")
                           .Save(GetTempFileName());

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log);

            loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            Log.HasLoggedErrors.ShouldBe(true);

            _buildEngine.LoggedEvents.Count.ShouldBe(1);
            BuildErrorEventArgs errorEvent = _buildEngine.LoggedEvents.FirstOrDefault() as BuildErrorEventArgs;

            errorEvent.ShouldNotBeNull();

            errorEvent?.Message.ShouldStartWith("The project file could not be loaded. Could not find file ");
        }
        public void TraversalReferencesWork()
        {
            var projectB = ProjectBuilder.Create()
                           .Save(GetTempFileName());

            var projectA = ProjectBuilder
                           .Create()
                           .AddProjectReference(projectB)
                           .Save(GetTempFileName());

            var dirsProj = ProjectBuilder
                           .Create()
                           .AddProperty("IsTraversal=true")
                           .AddItem($"ProjectFile={projectA.FullPath}")
                           .Save(GetTempFileName());

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, Log);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { dirsProj.FullPath, projectA.FullPath, projectB.FullPath });
        }