Skip to content

Commit

Permalink
Preserving COMReferences when transforming project files.
Browse files Browse the repository at this point in the history
Adding unit test to verify functionality.
  • Loading branch information
Diego Perez committed Jul 12, 2020
1 parent cfd2835 commit 30fca0c
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public sealed class FileTransformation : ILegacyOnlyProjectTransformation
"Reference",
"ProjectReference",
"PackageReference",
"COMReference",
"Antlr4",
"Antlr3"
};
Expand Down
25 changes: 25 additions & 0 deletions Project2015To2017.Tests/FileTransformationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Project2015To2017.Migrate2017.Transforms;
using Project2015To2017.Reading;
Expand Down Expand Up @@ -119,5 +120,29 @@ public void TransformsFiles()
Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "SourceFileAsResource.cs"));
Assert.IsTrue(removeMatchingWildcard.Any(x => x.Attribute("Remove")?.Value == "Class1.cs"));
}

[TestMethod]
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);
}
}
}
3 changes: 3 additions & 0 deletions Project2015To2017.Tests/Project2015To2017.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<None Include="TestFiles\FileInclusion\fileinclusion.testcsproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestFiles\FileInclusion\projectWithCOMRefs.testcsproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestFiles\FileInclusion\Folder\FileIncludedByWildcard.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion />
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{215B1102-3351-4C2B-BCC3-198013BBDB66}</ProjectGuid>
<MyType>WindowsForms</MyType>
<AssemblyName>Project1</AssemblyName>
<OutputType>WinExe</OutputType>
<StartupObject>Project1.Form1</StartupObject>
<AssemblyMajorVersion>1</AssemblyMajorVersion>
<AssemblyMinorVersion>0</AssemblyMinorVersion>
<AssemblyRevisionNumber>0</AssemblyRevisionNumber>
<RootNamespace>Project1</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<DefineDebug>True</DefineDebug>
<DefineTrace>True</DefineTrace>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE;Win32,Project1</DefineConstants>
<PlatformTarget>x86</PlatformTarget>
<StartArguments />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugSymbols>False</DebugSymbols>
<DefineDebug>False</DefineDebug>
<DefineTrace>True</DefineTrace>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE;Win32,Project1</DefineConstants>
<PlatformTarget>x86</PlatformTarget>
<StartArguments />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.XML" />
<Reference Include="Microsoft.CSharp" />
<ProjectReference Include="..\UpgradeSupport\UpgradeHelpers.Gui\UpgradeHelpers.Gui.csproj">
<Project>{F852374C-22BA-4CB6-AA34-DA1A589B9D8D}</Project>
<Name>UpgradeHelpers.Gui</Name>
</ProjectReference>
<COMReference Include="MSXML2">
<Guid>{F5078F18-C551-11D3-89B9-0000F81FE221}</Guid>
<Lcid>0</Lcid>
<VersionMajor>6</VersionMajor>
<VersionMinor>0</VersionMinor>
<WrapperTool>tlbimp</WrapperTool>
</COMReference>
<Reference Include="Microsoft.VisualBasic.Compatibility.Data" />
<Reference Include="MSDATASRC">
<Name>MSDATASRC</Name>
</Reference>
<COMReference Include="Microsoft.StdFormat">
<Guid>{6B263850-900B-11D0-9484-00A0C91110ED}</Guid>
<Lcid>0</Lcid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<WrapperTool>primary</WrapperTool>
</COMReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ExtendedMappings.xml" />
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<EmbeddedResource Include="Form1.resX">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Project1_UpgradeReport.htm">
<Subtype>Preview</Subtype>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit 30fca0c

Please sign in to comment.