Skip to content

Commit 4200ed3

Browse files
author
Zubin Ramlakhan
committed
- SlnConverter now includes dirname in regex search
- Adjusted UT for case part of proj name equals other proj name.
1 parent 2fe3223 commit 4200ed3

81 files changed

Lines changed: 3486 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CodeConverter/Shared/PathConverter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace ICSharpCode.CodeConverter.Shared
55
{
6+
using System.Text.RegularExpressions;
7+
68
internal static class PathConverter
79
{
810
public static string TogglePathExtension(string filePath)
@@ -33,5 +35,13 @@ private static string GetConvertedExtension(string originalExtension)
3335
return originalExtension;
3436
}
3537
}
38+
39+
public static string GetFileDirPath(string fileName, string dirPath)
40+
{
41+
var dirName = Path.GetFileName(dirPath);
42+
var fileDirPath = Path.Combine(dirName ?? string.Empty, fileName);
43+
44+
return fileDirPath;
45+
}
3646
}
3747
}

CodeConverter/Shared/SolutionConverter.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace ICSharpCode.CodeConverter.Shared
1111
{
12+
using ICSharpCode.CodeConverter.CSharp;
13+
1214
public class SolutionConverter
1315
{
1416
private readonly string _solutionFilePath;
@@ -24,7 +26,7 @@ public static SolutionConverter CreateFor<TLanguageConversion>(IReadOnlyCollecti
2426
IProgress<ConversionProgress> progress = null,
2527
CancellationToken cancellationToken = default) where TLanguageConversion : ILanguageConversion, new()
2628
{
27-
var conversion = new TLanguageConversion {ConversionOptions = conversionOptions };
29+
var conversion = new TLanguageConversion { ConversionOptions = conversionOptions };
2830
return CreateFor(conversion, projectsToConvert, progress, cancellationToken);
2931
}
3032

@@ -89,12 +91,19 @@ private IEnumerable<ConversionResult> UpdateProjectReferences(IEnumerable<Projec
8991
string sourceSolutionContents)
9092
{
9193
var projectReferenceReplacements = new List<(string Find, string Replace, bool FirstOnly)>();
92-
foreach (var project in projectsToConvert)
93-
{
94+
foreach (var project in projectsToConvert) {
9495
var projFilename = Path.GetFileName(project.FilePath);
96+
var projDirPath = project.GetDirectoryPath();
97+
9598
var newProjFilename = PathConverter.TogglePathExtension(projFilename);
96-
projectReferenceReplacements.Add((projFilename, newProjFilename, false));
97-
if (!string.IsNullOrWhiteSpace(sourceSolutionContents)) projectReferenceReplacements.Add(GetProjectGuidReplacement(projFilename, sourceSolutionContents));
99+
100+
var projPath = PathConverter.GetFileDirPath(projFilename, projDirPath);
101+
var newProjPath = PathConverter.GetFileDirPath(newProjFilename, projDirPath);
102+
103+
var projPathEscaped = Regex.Escape(projPath);
104+
105+
projectReferenceReplacements.Add((projPathEscaped, newProjPath, false));
106+
if (!string.IsNullOrWhiteSpace(sourceSolutionContents)) projectReferenceReplacements.Add(GetProjectGuidReplacement(projPathEscaped, sourceSolutionContents));
98107
}
99108

100109
return projectReferenceReplacements;
@@ -112,9 +121,9 @@ private ConversionResult ConvertSolutionFile()
112121
};
113122
}
114123

115-
private static (string Find, string Replace, bool FirstOnly) GetProjectGuidReplacement(string projFilename, string contents)
124+
private static (string Find, string Replace, bool FirstOnly) GetProjectGuidReplacement(string projPath, string contents)
116125
{
117-
var projGuidRegex = new Regex(projFilename + @""", ""({[0-9A-Fa-f\-]{32,36}})("")");
126+
var projGuidRegex = new Regex(projPath + @""", ""({[0-9A-Fa-f\-]{32,36}})("")");
118127
var projGuidMatch = projGuidRegex.Match(contents);
119128
var oldGuid = projGuidMatch.Groups[1].Value;
120129
var newGuid = GetDeterministicGuidFrom(new Guid(oldGuid));

Tests/CSharp/MultiFileSolutionAndProjectTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ public MultiFileSolutionAndProjectTests(MultiFileTestFixture multiFileTestFixtur
1919
_multiFileTestFixture = multiFileTestFixture;
2020
}
2121

22-
[Fact(Skip = "Doesn't work on Github actions agent")]
22+
//[Fact(Skip = "Doesn't work on Github actions agent")]
23+
[Fact]
2324
public async Task ConvertWholeSolutionAsync()
2425
{
2526

2627
await _multiFileTestFixture.ConvertProjectsWhereAsync(p => true, Language.CS);
2728
}
2829

29-
[Fact(Skip = "Doesn't work on Github actions agent")]
30+
[Fact]
3031
public async Task ConvertVbLibraryOnlyAsync()
3132
{
3233
await _multiFileTestFixture.ConvertProjectsWhereAsync(p => p.Name == "VbLibrary", Language.CS);

Tests/TestData/MultiFileCharacterization/SourceFiles/CharacterizationTestSolution.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "ConsoleApp4", "ConsoleApp4\
2222
EndProject
2323
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpNetStandardLib", "CSharpNetStandardLib\CSharpNetStandardLib.csproj", "{4DE39D59-19C6-4E1E-910C-5EA8BA55348B}"
2424
EndProject
25+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Prefix.VbLibrary", "Prefix.VbLibrary\Prefix.VbLibrary.vbproj", "{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -56,6 +58,10 @@ Global
5658
{4DE39D59-19C6-4E1E-910C-5EA8BA55348B}.Debug|Any CPU.Build.0 = Debug|Any CPU
5759
{4DE39D59-19C6-4E1E-910C-5EA8BA55348B}.Release|Any CPU.ActiveCfg = Release|Any CPU
5860
{4DE39D59-19C6-4E1E-910C-5EA8BA55348B}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{CFAB82CD-BA17-4F08-99E2-403FADB0C46A}.Release|Any CPU.Build.0 = Release|Any CPU
5965
EndGlobalSection
6066
GlobalSection(SolutionProperties) = preSolution
6167
HideSolutionNode = FALSE
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Friend Class AClass
2+
Enum NestedEnum
3+
First
4+
End Enum
5+
6+
Private dict As New Dictionary(Of Integer, Integer)
7+
Private anInt As Integer = 2
8+
Private anIntWithNonStaticInitializerReferencingOtherPart As Integer = anArrayWithNonStaticInitializerReferencingOtherPart.Length
9+
10+
Private Sub UseOutParameterInClass()
11+
Dim x
12+
dict.TryGetValue(1, x)
13+
End Sub
14+
15+
Private Sub UseEnumFromOtherFileInSolution(m As AnEnum)
16+
Dim [nothing] = Enumerable.Empty(Of String).ToArray()(AnEnum.AnEnumMember)
17+
Select Case m
18+
Case -1
19+
Exit Sub
20+
Case AnEnum.AnEnumMember
21+
Exit Sub
22+
End Select
23+
End Sub
24+
End Class
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Friend Enum AnEnum
2+
AnEnumMember
3+
End Enum
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Imports System
2+
3+
Module Module1
4+
Private dict As New Dictionary(Of Integer, Integer)
5+
6+
Private Sub UseOutParameterInModule()
7+
Dim x
8+
dict.TryGetValue(1, x)
9+
End Sub
10+
11+
Sub Main()
12+
Console.Write(AClass.NestedEnum.First)
13+
End Sub
14+
15+
End Module

Tests/TestData/MultiFileCharacterization/SourceFiles/Prefix.VbLibrary/My Project/Application.Designer.vb

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3+
<MySubMain>false</MySubMain>
4+
<SingleInstance>false</SingleInstance>
5+
<ShutdownMode>0</ShutdownMode>
6+
<EnableVisualStyles>true</EnableVisualStyles>
7+
<AuthenticationMode>0</AuthenticationMode>
8+
<ApplicationType>1</ApplicationType>
9+
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
10+
</MyApplicationData>

0 commit comments

Comments
 (0)