-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixup project reference paths during file-based app conversion #50860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,125 @@ public void SameAsTemplate() | |
.And.StartWith("""<Project Sdk="Microsoft.NET.Sdk">"""); | ||
} | ||
|
||
[Theory] // https://github.com/dotnet/sdk/issues/50832 | ||
[InlineData("File", "Lib", "../Lib", "Project", "../Lib/lib.csproj")] | ||
[InlineData(".", "Lib", "./Lib", "Project", "../Lib/lib.csproj")] | ||
[InlineData(".", "Lib", "Lib/../Lib", "Project", "../Lib/lib.csproj")] | ||
[InlineData("File", "Lib", "../Lib", "File/Project", "../../Lib/lib.csproj")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider also testing a case where the original path has redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider also testing both windows and unix path separators. |
||
[InlineData("File", "Lib", "..\\Lib", "File/Project", "../../Lib/lib.csproj")] | ||
public void ProjectReference_RelativePaths(string fileDir, string libraryDir, string reference, string outputDir, string convertedReference) | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
|
||
var libraryDirFullPath = Path.Join(testInstance.Path, libraryDir); | ||
Directory.CreateDirectory(libraryDirFullPath); | ||
File.WriteAllText(Path.Join(libraryDirFullPath, "lib.cs"), """ | ||
public static class C | ||
{ | ||
public static void M() | ||
{ | ||
System.Console.WriteLine("Hello from library"); | ||
} | ||
} | ||
"""); | ||
File.WriteAllText(Path.Join(libraryDirFullPath, "lib.csproj"), $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>{ToolsetInfo.CurrentTargetFramework}</TargetFramework> | ||
</PropertyGroup> | ||
</Project> | ||
"""); | ||
|
||
var fileDirFullPath = Path.Join(testInstance.Path, fileDir); | ||
Directory.CreateDirectory(fileDirFullPath); | ||
File.WriteAllText(Path.Join(fileDirFullPath, "app.cs"), $""" | ||
#:project {reference} | ||
C.M(); | ||
"""); | ||
|
||
var expectedOutput = "Hello from library"; | ||
|
||
new DotnetCommand(Log, "run", "app.cs") | ||
.WithWorkingDirectory(fileDirFullPath) | ||
.Execute() | ||
.Should().Pass() | ||
.And.HaveStdOut(expectedOutput); | ||
|
||
var outputDirFullPath = Path.Join(testInstance.Path, outputDir); | ||
new DotnetCommand(Log, "project", "convert", "app.cs", "-o", outputDirFullPath) | ||
.WithWorkingDirectory(fileDirFullPath) | ||
.Execute() | ||
.Should().Pass(); | ||
|
||
new DotnetCommand(Log, "run") | ||
.WithWorkingDirectory(outputDirFullPath) | ||
.Execute() | ||
.Should().Pass() | ||
.And.HaveStdOut(expectedOutput); | ||
|
||
File.ReadAllText(Path.Join(outputDirFullPath, "app.csproj")) | ||
.Should().Contain($""" | ||
<ProjectReference Include="{convertedReference.Replace('/', Path.DirectorySeparatorChar)}" /> | ||
"""); | ||
} | ||
|
||
[Fact] // https://github.com/dotnet/sdk/issues/50832 | ||
public void ProjectReference_FullPath() | ||
{ | ||
var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
|
||
var libraryDirFullPath = Path.Join(testInstance.Path, "Lib"); | ||
Directory.CreateDirectory(libraryDirFullPath); | ||
File.WriteAllText(Path.Join(libraryDirFullPath, "lib.cs"), """ | ||
public static class C | ||
{ | ||
public static void M() | ||
{ | ||
System.Console.WriteLine("Hello from library"); | ||
} | ||
} | ||
"""); | ||
File.WriteAllText(Path.Join(libraryDirFullPath, "lib.csproj"), $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>{ToolsetInfo.CurrentTargetFramework}</TargetFramework> | ||
</PropertyGroup> | ||
</Project> | ||
"""); | ||
|
||
var fileDirFullPath = Path.Join(testInstance.Path, "File"); | ||
Directory.CreateDirectory(fileDirFullPath); | ||
File.WriteAllText(Path.Join(fileDirFullPath, "app.cs"), $""" | ||
#:project {libraryDirFullPath} | ||
C.M(); | ||
"""); | ||
|
||
var expectedOutput = "Hello from library"; | ||
|
||
new DotnetCommand(Log, "run", "app.cs") | ||
.WithWorkingDirectory(fileDirFullPath) | ||
.Execute() | ||
.Should().Pass() | ||
.And.HaveStdOut(expectedOutput); | ||
|
||
var outputDirFullPath = Path.Join(testInstance.Path, "File/Project"); | ||
new DotnetCommand(Log, "project", "convert", "app.cs", "-o", outputDirFullPath) | ||
.WithWorkingDirectory(fileDirFullPath) | ||
.Execute() | ||
.Should().Pass(); | ||
|
||
new DotnetCommand(Log, "run") | ||
.WithWorkingDirectory(outputDirFullPath) | ||
.Execute() | ||
.Should().Pass() | ||
.And.HaveStdOut(expectedOutput); | ||
|
||
File.ReadAllText(Path.Join(outputDirFullPath, "app.csproj")) | ||
.Should().Contain($""" | ||
<ProjectReference Include="{Path.Join(libraryDirFullPath, "lib.csproj")}" /> | ||
"""); | ||
} | ||
|
||
[Fact] | ||
public void DirectoryAlreadyExists() | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.