私は、問題を解決するための簡単なPowerShellスクリプトを作成しました。ここに興味のある人は誰でも入れてください:
param(
[Parameter(Mandatory=$true)]$package,
$solution = (Get-Item *.sln),
$nuget = "nuget.exe"
)
& $nuget update "$solution" -Id "$package"
$sln = Get-Content $solution
[regex]$regex = 'Project\("{.*?}"\) = ".*?", "(.*?\.csproj)", "{.*?}"'
$csprojs = $sln | Select-String $regex -AllMatches |
% {$_.Matches} |
% {$_.Groups[1].Value}
Foreach ($csproj_path in $csprojs) {
$csproj_path = Get-Item $csproj_path
Write-Host "Updating csproj: $csproj_path"
[xml]$csproj = Get-Content $csproj_path
Push-Location (Get-Item $csproj_path).Directory
$reference = $csproj.Project.ItemGroup.Reference | ? {$_.Include -like "$package,*"}
$old_include = [string]$reference.Include
$old_hintpath = [string]$reference.HintPath
$old_version = $old_include | Select-String 'Version=([\d\.]+?),' |
% {$_.Matches} |
% {$_.Groups[1].Value}
$all_packages = Get-ChildItem $old_hintpath.Substring(0, $old_hintpath.IndexOf($package))
$new_package_dir = $all_packages | ? {$_.Name -like "$package.[0-9.]*"} |
? {$_.Name -notlike "$package.$old_version"} |
Select -First 1
$new_version = $new_package_dir | Select-String "$package.([\d\.]+)" |
% {$_.Matches} |
% {$_.Groups[1].Value}
$dll = Get-ChildItem -Path $new_package_dir.FullName -Recurse -Include *.dll | Select -First 1
$reference.HintPath = [string](Get-Item $dll.FullName | Resolve-Path -Relative)
$reference.Include = $reference.Include.Replace("Version=$old_version","Version=$new_version")
Pop-Location
$csproj.Save($csproj_path)
}
どうやってナゲット? https://docs.nuget.org/ndocs/tools/nuget.exe-cli-referenceが答えには短すぎます:P – TigOldBitties
"nuget install My.Nuget.Package"を実行すると、ソリューションのパッケージ/フォルダにのみダウンロードされます。 packages.jsonファイル内のそのパッケージへの使用を実際には更新したり、csprojファイル内のhintpathを更新したりすることはありません。これらの2つのファイルを手動で更新するのは、ビジュアルスタジオを開くよりも高速ですが、エラーが発生しやすくなります(エラーが発生することが知られています)。 –
VSの外のファイルを編集する単純なVSショートカットを持つのはなぜですか? "nuget.exe install"、より具体的には "nuget.exe update"はほとんどの方法で私に教えてくれます。本当に残っているのは、package.config/*。csprojファイルにエントリを追加する "install"コマンドと、* .csprojファイルのヒントパスを更新する "update"コマンドだけです。私はコマンドを実行し、私が望むことをするためのクイックスクリプトを作ることができますが、これは今解決されているに違いないと思っていました。 –