我在以下链接的安装脚本中找到了一种解决方法:http ://www.jaylee.org/post/2011/11/25/NuGet-package-customizations-and-optional-references.aspx
我不得不通过反复试验进行一些修改,最后做出了这个改变:
# removed the + sign in *?\\ and removed the double trailing backslash
$newHintPath = $hintPath -replace "$packageId.*?\\", "$packageName\"
最终脚本现在如下所示:
$packageName = $package.Id + '.' + $package.Version;
$packageId = $package.Id;
# Full assembly name is required
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection
# There is no indexer on ICollection<T> and we cannot call
# Enumerable.First<T> because Powershell does not support it easily and
# we do not want to end up MethodInfo.MakeGenericMethod.
$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator();
Write-Host "Replace hint paths in project"
if($allProjects.MoveNext())
{
foreach($item in $allProjects.Current.GetItems("Reference"))
{
$hintPath = $item.GetMetadataValue("HintPath")
$newHintPath = $hintPath -replace "$packageId.*?\\", "$packageName\"
if($hintPath -ne $newHintPath)
{
Write-Host "Updating $hintPath to $newHintPath"
$item.SetMetadataValue("HintPath", $newHintPath);
}
}
}