Exemple #1
0
        public static TConfiguration UseFileTransformation <TConfiguration>(this TConfiguration configuration, string file, Action <IFileTransformation> transformerAction, StepType onStep = StepType.PreBuild)
            where TConfiguration : IConfiguration
        {
            IFileTransformationAction transformation = new FileTransformation();

            transformerAction(transformation);
            configuration.AddStep(new FileTransformationStep(file, transformation, onStep));
            return(configuration);
        }
Exemple #2
0
        public void TransformsFilesExclude()
        {
            var project = new ProjectReader().Read(Path.Combine("TestFiles", "FileInclusion", "fileExclusion.testcsproj"));

            project.CodeFileExtension = "cs";
            var transformation = new FileTransformation();

            transformation.Transform(project);

            var includeItems = project.ItemGroups.SelectMany(x => x.Elements()).ToImmutableList();

            Assert.AreEqual(1, includeItems.Count(x => x.Name.LocalName == "Compile" && x.Attribute("Remove")?.Value == "Program.cs"));
        }
        public async Task TransformsFiles()
        {
            var project        = new Project();
            var transformation = new FileTransformation();

            var directoryInfo = new DirectoryInfo(".\\TestFiles");
            var doc           = XDocument.Load("TestFiles\\fileinclusion.testcsproj");

            await transformation.TransformAsync(doc, directoryInfo, project).ConfigureAwait(false);

            Assert.AreEqual(6, project.ItemsToInclude.Count);

            XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003";

            Assert.AreEqual(1, project.ItemsToInclude.Count(x => x.Name == nsSys + "Compile"));
            Assert.AreEqual(2, project.ItemsToInclude.Count(x => x.Name == "Compile"));
            Assert.AreEqual(2, project.ItemsToInclude.Count(x => x.Name == "Compile" && x.Attribute("Update") != null));
            Assert.AreEqual(0, project.ItemsToInclude.Count(x => x.Name == nsSys + "EmbeddedResource"));
            Assert.AreEqual(1, project.ItemsToInclude.Count(x => x.Name == nsSys + "Content"));
            Assert.AreEqual(2, project.ItemsToInclude.Count(x => x.Name == nsSys + "None"));
        }
        public void TransformsFilesPreserveCOMReferences()
        {
            var project = new ProjectReader().Read(Path.Combine("TestFiles", "FileInclusion", "projectWithCOMRefs.testcsproj"));

            project.CodeFileExtension = "cs";
            var transformation = new FileTransformation();

            var comReferencesBefore = project.ProjectDocument.Root.DescendantNodes().
                                      Where(node => node.NodeType == System.Xml.XmlNodeType.Element).
                                      Where(node => (node as XElement).Name.LocalName.Equals("COMReference")).ToList();

            Assert.AreEqual(2, comReferencesBefore.Count);

            transformation.Transform(project);

            var comReferencesAfter = project.ProjectDocument.Root.DescendantNodes().
                                     Where(node => node.NodeType == System.Xml.XmlNodeType.Element).
                                     Where(node => (node as XElement).Name.LocalName.Equals("COMReference")).ToList();

            Assert.AreEqual(2, comReferencesAfter.Count);
            Assert.AreEqual((comReferencesBefore[0] as XElement).Value, (comReferencesAfter[0] as XElement).Value);
            Assert.AreEqual((comReferencesBefore[1] as XElement).Value, (comReferencesAfter[1] as XElement).Value);
        }
Exemple #5
0
        public void TransformsFiles()
        {
            var project = new ProjectReader().Read(Path.Combine("TestFiles", "FileInclusion", "fileinclusion.testcsproj"));

            project.CodeFileExtension = "cs";
            var transformation = new FileTransformation();

            transformation.Transform(project);

            var includeItems = project.ItemGroups.SelectMany(x => x.Elements()).ToImmutableList();

            Assert.AreEqual(32, includeItems.Count);

            Assert.AreEqual(12, includeItems.Count(x => x.Name.LocalName == "Reference"));
            Assert.AreEqual(2, includeItems.Count(x => x.Name.LocalName == "ProjectReference"));
            Assert.AreEqual(2, includeItems.Count(x => x.Name.LocalName.Equals("Antlr4")));
            Assert.AreEqual(1, includeItems.Count(x => x.Name.LocalName.Equals("Antlr3")));
            Assert.AreEqual(11, includeItems.Count(x => x.Name.LocalName == "Compile"));
            Assert.AreEqual(5, includeItems.Count(x => x.Name.LocalName == "Compile" && x.Attribute("Update") != null));
            Assert.AreEqual(4, includeItems.Count(x => x.Name.LocalName == "Compile" && x.Attribute("Include") != null));
            Assert.AreEqual(2, includeItems.Count(x => x.Name.LocalName == "Compile" && x.Attribute("Remove") != null));
            Assert.AreEqual(3, includeItems.Count(x => x.Name.LocalName == "EmbeddedResource"));             // #73 include things that are not ending in .resx
            Assert.AreEqual(0, includeItems.Count(x => x.Name.LocalName == "Content"));
            Assert.AreEqual(1, includeItems.Count(x => x.Name.LocalName == "None"));
            Assert.AreEqual(0, includeItems.Count(x => x.Name.LocalName == "Analyzer"));

            var resourceDesigner = includeItems.Single(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Update")?.Value == @"Properties\Resources.Designer.cs"
                );

            Assert.AreEqual(3, resourceDesigner.Elements().Count());
            var dependentUponElement = resourceDesigner.Elements().Single(x => x.Name.LocalName == "DependentUpon");

            Assert.AreEqual("Resources.resx", dependentUponElement.Value);

            var linkedFile = includeItems.Single(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Include")?.Value == @"..\OtherTestProjects\OtherTestClass.cs"
                );
            var linkAttribute = linkedFile.Attributes().FirstOrDefault(a => a.Name.LocalName == "Link");

            Assert.IsNotNull(linkAttribute);
            Assert.AreEqual("OtherTestClass.cs", linkAttribute.Value);

            var sourceWithDesigner = includeItems.Single(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Update")?.Value == @"SourceFileWithDesigner.cs"
                );

            var subTypeElement = sourceWithDesigner.Elements().Single();

            Assert.AreEqual("SubType", subTypeElement.Name.LocalName);
            Assert.AreEqual("Component", subTypeElement.Value);

            var designerForSource = includeItems.Single(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Update")?.Value == @"SourceFileWithDesigner.Designer.cs"
                );

            var dependentUponElement2 = designerForSource.Elements().Single();

            Assert.AreEqual("DependentUpon", dependentUponElement2.Name.LocalName);
            Assert.AreEqual("SourceFileWithDesigner.cs", dependentUponElement2.Value);

            var fileWithAnotherAttribute = includeItems.Single(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Update")?.Value == @"AnotherFile.cs"
                );

            Assert.AreEqual(2, fileWithAnotherAttribute.Attributes().Count());
            Assert.AreEqual("AttrValue", fileWithAnotherAttribute.Attribute("AnotherAttribute")?.Value);

            var removeMatchingWildcard = includeItems.Where(
                x => x.Name.LocalName == "Compile" &&
                x.Attribute("Remove")?.Value != null
                )
                                         .ToImmutableList();

            Assert.IsNotNull(removeMatchingWildcard);
            Assert.AreEqual(2, removeMatchingWildcard.Count);
            Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "SourceFileAsResource.cs"));
            Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "Class1.cs"));
        }
Exemple #6
0
        public void TransformsFiles()
        {
            var project        = new ProjectReader(Path.Combine("TestFiles", "FileInclusion", "fileinclusion.testcsproj")).Read();
            var transformation = new FileTransformation();

            var logEntries = new List <string>();

            var progress = new Progress <string>(x => { logEntries.Add(x); });

            transformation.Transform(project, progress);

            var includeItems = project.IncludeItems;

            Assert.AreEqual(13, includeItems.Count);

            Assert.AreEqual(9, includeItems.Count(x => x.Name == project.XmlNamespace + "Compile"));
            Assert.AreEqual(6, includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Update") != null));
            Assert.AreEqual(1, includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Include") != null));
            Assert.AreEqual(2, includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Remove") != null));
            Assert.AreEqual(2, includeItems.Count(x => x.Name == project.XmlNamespace + "EmbeddedResource"));             // #73 inlcude things that are not ending in .resx
            Assert.AreEqual(0, includeItems.Count(x => x.Name == project.XmlNamespace + "Content"));
            Assert.AreEqual(2, includeItems.Count(x => x.Name == project.XmlNamespace + "None"));

            var resourceDesigner = includeItems.Single(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Update")?.Value == @"Properties\Resources.Designer.cs"
                );

            Assert.AreEqual(3, resourceDesigner.Elements().Count());
            var dependentUponElement = resourceDesigner.Elements().Single(x => x.Name == project.XmlNamespace + "DependentUpon");

            Assert.AreEqual("Resources.resx", dependentUponElement.Value);

            var linkedFile = includeItems.Single(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Include")?.Value == @"..\OtherTestProjects\OtherTestClass.cs"
                );
            var linkAttribute = linkedFile.Attributes().FirstOrDefault(a => a.Name == "Link");

            Assert.IsNotNull(linkAttribute);
            Assert.AreEqual("OtherTestClass.cs", linkAttribute.Value);

            var sourceWithDesigner = includeItems.Single(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Update")?.Value == @"SourceFileWithDesigner.cs"
                );

            var subTypeElement = sourceWithDesigner.Elements().Single();

            Assert.AreEqual(project.XmlNamespace + "SubType", subTypeElement.Name);
            Assert.AreEqual("Component", subTypeElement.Value);

            var designerForSource = includeItems.Single(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Update")?.Value == @"SourceFileWithDesigner.Designer.cs"
                );

            var dependentUponElement2 = designerForSource.Elements().Single();

            Assert.AreEqual(project.XmlNamespace + "DependentUpon", dependentUponElement2.Name);
            Assert.AreEqual("SourceFileWithDesigner.cs", dependentUponElement2.Value);

            var fileWithAnotherAttribute = includeItems.Single(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Update")?.Value == @"AnotherFile.cs"
                );

            Assert.AreEqual(2, fileWithAnotherAttribute.Attributes().Count());
            Assert.AreEqual("AttrValue", fileWithAnotherAttribute.Attribute("AnotherAttribute")?.Value);

            var removeMatchingWildcard = includeItems.Where(
                x => x.Name == project.XmlNamespace + "Compile" &&
                x.Attribute("Remove")?.Value != null
                );

            Assert.IsNotNull(removeMatchingWildcard);
            Assert.AreEqual(2, removeMatchingWildcard.Count());
            Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "SourceFileAsResource.cs"));
            Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "Class1.cs"));

            //<Compile Include="AnotherFile.cs" AnotherAttribute="AttrValue" />
            var warningLogEntries = logEntries
                                    .Where(x => x.StartsWith("File found") || x.StartsWith("File was included"))
                                    //todo: would be good to be able to remove this condition and not warn on wildcard inclusions
                                    //that are covered by main wildcard
                                    .Where(x => !x.ToUpper().Contains("WILDCARD"));

            Assert.IsFalse(warningLogEntries.Any());
        }
Exemple #7
0
        public async Task TransformsPresentationPages()
        {
            var project = await ParseAndTransform(@"
<Project ToolsVersion=""14.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <AssemblyName>Dopamine</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DefineConstants>TRACE;DEBUG;WINDOWS_DESKTOP</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DefineConstants>TRACE</DefineConstants>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationIcon>Dopamine.ico</ApplicationIcon>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationManifest>app.manifest</ApplicationManifest>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include=""System"" />
    <Reference Include=""System.Net.Http"" />
    <Reference Include=""System.Xaml"">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include=""PresentationCore"" />
    <Reference Include=""PresentationFramework"" />
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include=""App.xaml"">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Compile Include=""App.xaml.cs"">
      <DependentUpon>App.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
    <Compile Include=""Views\Shell.xaml.cs"">
      <DependentUpon>Shell.xaml</DependentUpon>
    </Compile>
    <Compile Include="".\..\Views\Initialize.xaml.cs"">
      <DependentUpon>Initialize.xaml</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <Page Include=""Views\Shell.xaml"">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="".\..\Views\Initialize.xaml"">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
  </ItemGroup>
</Project>");

            Assert.IsTrue(project.IsWindowsPresentationFoundationProject);
            Assert.IsFalse(project.IsWindowsFormsProject);

            Assert.AreEqual(1, project.TargetFrameworks.Count);
            Assert.AreEqual(1, project.TargetFrameworks.Count(x => x == "net461"));

            Assert.AreEqual(2, project.Configurations.Count);
            Assert.AreEqual(1, project.Configurations.Count(x => x == "Debug"));
            Assert.AreEqual(1, project.Configurations.Count(x => x == "Release"));

            Assert.AreEqual(1, project.Platforms.Count);
            Assert.AreEqual(1, project.Platforms.Count(x => x == "AnyCPU"));

            Assert.AreEqual(3, project.AdditionalPropertyGroups.Count);

            Assert.IsNotNull(project.AdditionalPropertyGroups[0].Attribute("Condition"));
            Assert.IsNotNull(project.AdditionalPropertyGroups[1].Attribute("Condition"));
            Assert.IsNull(project.AdditionalPropertyGroups[2].Attribute("Condition"));

            var childrenDebug = project.AdditionalPropertyGroups[0].Elements().ToImmutableArray();

            Assert.AreEqual(1, childrenDebug.Length);
            // non-standard additional WINDOWS_DESKTOP constant present only in Debug
            Assert.IsTrue(ProjectPropertiesReadTest.ValidateChildren(childrenDebug, "DefineConstants"));

            var childrenRelease = project.AdditionalPropertyGroups[1].Elements().ToImmutableArray();

            Assert.AreEqual(0, childrenRelease.Length);

            var childrenGlobal = project.AdditionalPropertyGroups[2].Elements().ToImmutableArray();

            Assert.AreEqual(3, childrenGlobal.Length);
            Assert.IsTrue(ProjectPropertiesReadTest.ValidateChildren(childrenGlobal,
                                                                     "ProjectTypeGuids", "ApplicationIcon", "ApplicationManifest"));

            var fileTransformation = new FileTransformation();
            var transformation     = new XamlPagesTransformation();

            var progress = new Progress <string>();

            fileTransformation.Transform(project, progress);
            transformation.Transform(project, progress);

            var includeItems = project.IncludeItems;

            // App.xaml is NOT included due to ApplicationDefinition
            // App.xaml.cs is NOT included due to <SubType>Code</SubType> (FileTransformation)
            // Views\Shell.xaml.cs is NOT included due to Compile+DependentUpon
            // .\..\Views\Initialize.xaml.cs is included due to not in project folder
            // Views\Shell.xaml is NOT included due to Page
            // .\..\Views\Initialize.xaml is included due to Page not in project folder

            Assert.AreEqual(2, includeItems.Count);

            Assert.AreEqual(1, includeItems.Count(x => x.Name == project.XmlNamespace + "Page"));
            Assert.AreEqual(0, includeItems.Count(x => x.Name == project.XmlNamespace + "ApplicationDefinition"));
            Assert.AreEqual(1, includeItems.Count(x => x.Name == project.XmlNamespace + "Compile"));
            Assert.AreEqual(1,
                            includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Update") != null));
            Assert.AreEqual(0,
                            includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Include") != null));
            Assert.AreEqual(0,
                            includeItems.Count(x => x.Name == project.XmlNamespace + "Compile" && x.Attribute("Remove") != null));
        }