Some paths converted to 8.3 to work around .NET 260 chars limit

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 10 years ago
parent fb7ae24780
commit 668730e1da
  1. 1
      DotNetBuilder/MicroBuildServer.DotNetBuilder.csproj
  2. 5
      DotNetBuilder/NuGetter.cs
  3. 57
      DotNetBuilder/PathTools.cs

@ -90,6 +90,7 @@
<Compile Include="NuGetPackRequest.cs" /> <Compile Include="NuGetPackRequest.cs" />
<Compile Include="NuGetPushRequest.cs" /> <Compile Include="NuGetPushRequest.cs" />
<Compile Include="NuGetter.cs" /> <Compile Include="NuGetter.cs" />
<Compile Include="PathTools.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Response.cs" /> <Compile Include="Response.cs" />

@ -166,10 +166,11 @@ namespace MicroBuildServer.DotNetBuilder
public static Response Pack(NuGetPackRequest request) public static Response Pack(NuGetPackRequest request)
{ {
var console = new Console(); var console = new Console();
PackageBuilder builder = new PackageBuilder();
var command = new PackCommand var command = new PackCommand
{ {
BasePath = request.BaseDirectory, BasePath = PathTools.OptimizePath(request.BaseDirectory),
OutputDirectory = request.OutputDirectory, OutputDirectory = PathTools.OptimizePath(request.OutputDirectory),
Version = request.Version, Version = request.Version,
Console = console, Console = console,
Verbosity = Verbosity.Detailed, Verbosity = Verbosity.Detailed,

@ -0,0 +1,57 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace MicroBuildServer.DotNetBuilder
{
static class PathTools
{
private const string UNC_PREFIX = "\\\\?\\";
const int MAX_PATH = 255;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength);
private static string GetShortPath(string path)
{
var shortPath = new StringBuilder(MAX_PATH);
GetShortPathName(path, shortPath, MAX_PATH);
return shortPath.ToString();
}
private static string OptimizeDirectoryPath(string fullPath)
{
var uncPath = UNC_PREFIX + fullPath;
var shortPath = GetShortPath(uncPath);
if (shortPath.StartsWith(UNC_PREFIX))
{
shortPath = shortPath.Substring(UNC_PREFIX.Length);
}
return shortPath;
}
public static string OptimizePath(string rawPath)
{
//Console.WriteLine(rawPath);
var fullPath = Path.GetFullPath(new Uri(rawPath).LocalPath);
string result;
if (Directory.Exists(fullPath))
{
result = OptimizeDirectoryPath(fullPath);
}
else
{
var directoryPath = Path.GetDirectoryName(fullPath);
var optimizedDirectoryPath = OptimizeDirectoryPath(directoryPath);
result = Path.Combine(optimizedDirectoryPath, Path.GetFileName(fullPath));
}
//Console.WriteLine(result);
return result;
}
}
}
Loading…
Cancel
Save