I use Package Manager Console
to install Unity
package into my legacy projects in .NET Framework 4.5.2 that are placed in c:\%SOLUTION_BASE_PATH%\SomeFolder\SomeInnerFolder2\ParticularSolutionFolder
. I use this command:
Install-Package -ProjectName $ProjectName -Id Unity -Version 2.1.505.2 -Source nuget.org -Verbose -FileConflictAction IgnoreAll -ErrorAction Stop -WarningAction Ignore -IncludePrerelease
All is good, it works well. Now I want to change repositoryPath
in nuget.config
to install all packages for all my solutions into the same folder. I add the below lines to nuget.config
:
<config><add key="repositoryPath" value="c:\%SOLUTION_BASE_PATH%\packages" /></config>
Mostly it works well too, but Unity
packages gives me the below output and fails.
At first it works normally:
Added package 'Unity.2.1.505.2' to folder 'c:\%SOLUTION_BASE_PATH%\packages' from source ' https://api.nuget.org/v3/index.json' Added reference 'Microsoft.Practices.Unity.Configuration' to project:'X'. The Reference was Resolved To Package (resolvedToPackage):'True', where Reference Path from DTE(dteOriginalPath):'C:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll' and Reference Path from package reference(assemblyFullPath):'c:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll'. Added reference 'Microsoft.Practices.Unity' to project:'X'. The Reference was Resolved To Package (resolvedToPackage):'True', where Reference Path from DTE(dteOriginalPath):'C:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.dll' and Reference Path from package reference(assemblyFullPath):'c:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.dll'. Added package 'Unity.2.1.505.2' to 'packages.config'
but then fails with the below error:
Executing script file 'c:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\tools\install.ps1' Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger than length of string. Parameter name: startIndex" At C:\%SOLUTION_BASE_PATH%\packages\Unity.2.1.505.2\tools\Utils.psm1:71 char:12+ return ($targetPath.Substring($basePath.Length)).TrimStart([Syste ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : ArgumentOutOfRangeException
Then it just removes affected packages:
Removed package 'Unity.2.1.505.2 : CommonServiceLocator [1.0.0, )' from 'packages.config' Removed reference 'Microsoft.Practices.Unity.Configuration.dll' from project 'X' Removed reference 'Microsoft.Practices.Unity.dll' from project 'X' Removed package 'CommonServiceLocator.1.0.0' from 'packages.config' ...
and fails the whole run:
... Executing nuget actions took 5.91 sec The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot bind argument to parameter 'Path' because it is null.
It happens only on my work machine, so when I try it on another one it doesn't give any issues, so I can check the content inside the package that fails. The failed file has just these lines:
param($installPath, $toolsPath, $package, $project) Import-Module (Join-Path $toolsPath Utils.psm1) $relativeInstallPath = Get-RelativePath ([System.Io.Path]::GetDirectoryName($dte.Solution.FullName)) $installPath $folder = (Join-Path (Join-Path $relativeInstallPath "lib") "NET35") Add-ToolFolder $folder
where failed function is placed inside Utils.psm1:
function Get-RelativePath([System.String] $basePath, [System.String] $targetPath) { # not a general purpose relative path calculation algorithm return ($targetPath.Substring($basePath.Length)).TrimStart([System.Io.Path]::DirectorySeparatorChar) }
however, I'm not sure yet what's exacly wrong here. Any help would be appriciated.