Skip to content

Commit 4f0b7bd

Browse files
author
Livar
authored
Merge pull request #5364 from livarcocc/package_reference
Check that a folder contains a project before considering it a P2P dependency
2 parents 49c2a4b + f765a02 commit 4f0b7bd

File tree

8 files changed

+96
-12
lines changed

8 files changed

+96
-12
lines changed

TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App.Tests/.noautobuild

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace App.Tests
4+
{
5+
public class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
Console.WriteLine("Hello World!");
10+
}
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"frameworks": {
3+
"netcoreapp1.0": {
4+
"imports": [
5+
"portable-net451+win8",
6+
"dnxcore50"
7+
],
8+
"buildOptions": {
9+
"define": [ "ASYNC", "COREFX", "XUNIT2", "SQLITE" ]
10+
},
11+
"dependencies": {
12+
"Microsoft.NETCore.App": {
13+
"version": "1.0.0",
14+
"type": "platform"
15+
}
16+
}
17+
}
18+
}
19+
}

TestAssets/TestProjects/AppWithPackageNamedAfterFolder/App/.noautobuild

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"frameworks": {
3+
"net40": {
4+
"frameworkAssemblies": {
5+
"System.Configuration": "4.0.0.0",
6+
"System.Data": "4.0.0.0",
7+
"System.Data.Linq": "4.0.0.0",
8+
"System.Xml": "4.0.0.0"
9+
},
10+
"dependencies": {
11+
"EntityFramework": "6.1.3",
12+
"Microsoft.SqlServer.Types": "11.0.2"
13+
}
14+
},
15+
"net45": {
16+
"buildOptions": {
17+
"define": [ "ASYNC" ]
18+
},
19+
"frameworkAssemblies": {
20+
"System.Configuration": "4.0.0.0",
21+
"System.Data": "4.0.0.0",
22+
"System.Data.Linq": "4.0.0.0",
23+
"System.Xml": "4.0.0.0"
24+
},
25+
"dependencies": {
26+
"EntityFramework": "6.1.3",
27+
"Microsoft.SqlServer.Types": "11.0.2"
28+
}
29+
}
30+
}
31+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [
3+
"App",
4+
"App.Tests"
5+
]
6+
}

src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,24 +316,25 @@ private static List<ProjectDependency> GetPotentialProjects(
316316
foreach (var projectDirectory in
317317
Enumerable.Repeat(directory, 1).Union(directory.GetDirectories()))
318318
{
319-
// Create the path to the project.json file.
320-
var projectFilePath = Path.Combine(projectDirectory.FullName, "project.json");
321-
322-
// We INTENTIONALLY do not do an exists check here because it requires disk I/O
323-
// Instead, we'll do an exists check when we try to resolve
324-
325-
// Check if we've already added this, just in case it was pre-loaded into the cache
326-
var project = new ProjectDependency(
327-
projectDirectory.Name,
328-
projectFilePath);
329-
330-
projects.Add(project);
319+
AddIfProjectExists(projects, projectDirectory);
331320
}
332321
}
333322

334323
return projects;
335324
}
336325

326+
private static void AddIfProjectExists(List<ProjectDependency> projects, DirectoryInfo projectDirectory)
327+
{
328+
var projectJSONFilePath = Path.Combine(projectDirectory.FullName, "project.json");
329+
var csProjFilePath = Path.Combine(projectDirectory.FullName, $"{projectDirectory.Name}.csproj");
330+
331+
if (File.Exists(projectJSONFilePath) || File.Exists(csProjFilePath))
332+
{
333+
var project = new ProjectDependency(projectDirectory.Name, projectJSONFilePath);
334+
projects.Add(project);
335+
}
336+
}
337+
337338
internal static List<string> GetGlobalPaths(string rootPath)
338339
{
339340
var paths = new List<string>();

test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ public void ItMigratesAndPublishesWebApp()
163163
PublishMSBuild(projectDirectory, projectName);
164164
}
165165

166+
[Fact]
167+
public void ItMigratesAPackageReferenceAsSuchEvenIfAFolderWithTheSameNameExistsInTheRepo()
168+
{
169+
var solutionDirectory =
170+
TestAssetsManager.CreateTestInstance("AppWithPackageNamedAfterFolder").Path;
171+
var appProject = Path.Combine(solutionDirectory, "App", "App.csproj");
172+
173+
MigrateProject(solutionDirectory);
174+
175+
var projectRootElement = ProjectRootElement.Open(appProject);
176+
projectRootElement.Items.Where(
177+
i => i.Include == "EntityFramework" && i.ItemType == "PackageReference")
178+
.Should().HaveCount(2);
179+
}
180+
166181
[Fact]
167182
public void ItAddsMicrosoftNetWebSdkToTheSdkAttributeOfAWebApp()
168183
{

0 commit comments

Comments
 (0)