-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get correct casing for project paths (#9)
ProjectReference items do not always reflect the casing of a path according to the file system. When generating a Visual Studio solution, the path casing matters to NuGet.
- Loading branch information
Showing
5 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/SlnGen.Build.Tasks.UnitTests/ToFullPathInCorrectCaseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using System; | ||
using System.IO; | ||
|
||
namespace SlnGen.Build.Tasks.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ToFullPathInCorrectCaseTests | ||
{ | ||
[Test] | ||
public void IncorrectCaseInDirectory() | ||
{ | ||
ValidatePath(Path.GetTempFileName()); | ||
} | ||
|
||
[Test] | ||
public void IncorrectCaseInFile() | ||
{ | ||
string expectedPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid().ToString("N").ToUpperInvariant()}.txt"); | ||
|
||
File.WriteAllText(expectedPath, String.Empty); | ||
|
||
ValidatePath(expectedPath); | ||
} | ||
|
||
private void ValidatePath(string expectedPath) | ||
{ | ||
try | ||
{ | ||
expectedPath | ||
.ToLowerInvariant() | ||
.ToFullPathInCorrectCase() | ||
.ShouldBe(expectedPath); | ||
} | ||
finally | ||
{ | ||
File.Delete(expectedPath); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace SlnGen.Build.Tasks.Internal | ||
{ | ||
internal static class NativeMethods | ||
{ | ||
/// <summary> | ||
/// Converts the specified path to its long form. | ||
/// </summary> | ||
/// <param name="lpszShortPath">The path to be converted.</param> | ||
/// <param name="lpszLongPath">A pointer to the buffer to receive the long path.</param> | ||
/// <param name="cchBuffer">The size of the buffer lpszLongPath points to, in TCHARs.</param> | ||
/// <returns>If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszLongPath, not including the terminating null character. | ||
/// | ||
/// If the lpBuffer buffer is too small to contain the path, the return value is the size, in TCHARs, of the buffer that is required to hold the path and the terminating null character. | ||
/// | ||
/// If the function fails for any other reason, such as if the file does not exist, the return value is zero.To get extended error information, call GetLastError.</returns> | ||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
[return: MarshalAs(UnmanagedType.U4)] | ||
public static extern int GetLongPathName([MarshalAs(UnmanagedType.LPTStr)] string lpszShortPath, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszLongPath, [MarshalAs(UnmanagedType.U4)] int cchBuffer); | ||
} | ||
} |