sitemap contact get back to the top back next
$Date: 2018-07-07 06:49:13 +0900 (2018/07/07 (土)) $
$Revision: 1347 $

workaround for nuget.exe error that 'The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.'

Introduction

Pipeline Multibranch Plugin uses very long path as a workspace.
But nuget.exe has a limition on the max length to handle.
NuGet and long file name support #3324
This page explains how to maneuver this limitation.

Workaround Concept

  1. Create an unique path name for a temporary junction.
  2. Create an unique and temporary junction for a very long path directory.
  3. move to the directory of the junction.
  4. run 'nuget.exe restore' for all solution files in the sub directories.
  5. move to the original directory.
  6. remove the temporary junction.

how to create junction

You can create a junction by 'mklink /j'.

syntax

mklink /j <new junction path> <source directory path>

example

mklink /j C:\Windows\Temp\new-junction C:\Jenkins\workspace\sample-cmake-profile_master-IUZBDGO3W5L2BPWGQVT2S7PEJHL5ZITG5TGSZPXMOTZ4IVLY35GQ

how to remove junction

You can remove a junction by rmdir.

example

rmdir C:\Windows\Temp\new-junction

sample batch file to maneuver the limitation

download

Please rename '.txt' to '.bat' after downloading. sample batch file (restore-all.txt)

batch file

@rem This is a batch file to maneuver the limitaion of the max path length which nuget.exe can handle.
@rem 
@rem It is designed to use in a Jenkins Job because it relies on BUILD_TAG variable.
@rem If you want to use this outside of Jenkins, you need to choose an alternative unique id.
@rem
@rem 1. Create an unique path name for the next step.
@rem 2. Create a unique and temporary junction for very long path directory. 
@rem   (The path length of the temporary junction must be short enough.)
@rem 3. move to the directory of the junction.
@rem 4. remove all packages directories recursively. (not mandatory)
@rem 5. run 'nuget.exe restore' for all solution files recursively.
@rem 6. move to the original directory.
@rem 7. remove the temporary junction.

@echo off
set RET=1
@rem You may want to change the path of nuget.exe
set NUGET_PATH=C:\Program Files (x86)\NuGet\nuget.exe

@rem check environment variable of Jenkins
if "%BUILD_TAG%" == "" (
	echo BUILD_TAG is empty
	exit /b 1
)


@rem the parent directory of a temporary junction
@rem you may want to tweak this.
set WA_ROOT=C:\Windows\Temp


@rem path to temporary junction
@rem change this path if you need to.
@rem 
@rem BUILD_TAG and EXECUTOR_NUMBER are defined by Jenkins.
@rem see https://wiki.jenkins.io/display/JENKINS/Building+a+software+project
@rem 
set WA_TARGET=%WA_ROOT%\%BUILD_TAG%-%EXECUTOR_NUMBER%

@rem save current directory
set CURRENT=%CD%

@rem workspace directory which is the target directory of the junction
set WA_SOURCE=%CURRENT%


@rem create a temporary junction
@rem This is the first core of this workaround.
echo mklink /j "%WA_TARGET%" "%WA_SOURCE%"
     mklink /j "%WA_TARGET%" "%WA_SOURCE%"          || goto END

@rem move to the junction directory to avoid the limitation of nuget.exe.
@rem This is the second core of this workaround.
cd /d %WA_TARGET%                                   || goto END


@rem this is optional.
@rem If you don't need to remove packages directory in advance, disable or remove this.
for /r %%i in (packages) do (
	if exist %%i (
		echo rmdir /s /q %%i
		     rmdir /s /q %%i
	)
)

@rem run 'nuget.exe restore' recursively.
for /r %%i in (*.sln) do (
	if exist %%i (
		echo "%NUGET_PATH%" restore %%i
		     "%NUGET_PATH%" restore %%i || goto END
	)
)

@rem set return code
set RET=0

:END
@rem get back to the original directory.
cd /d %CURRENT%

@rem remove the temporary junction
echo rmdir %WA_TARGET%
     rmdir %WA_TARGET%

@rem return result
exit /b %RET%