システムの規模が大きくなると、昔は使っていたけど不要になったクラスファイルがVisual Studioで管理されていないけどWindowsのフォルダに物理的に残っちゃうことがよくあります。
そんな不要なファイルを探すPowerShellスクリプトはこちら。
// あるディレクトリ内でcsproj内で参照されている csファイルを抽出 完全ではないが、まぁ、なんとなく。
Get-ChildItem -Path "C:\Users\koki\Documents\Visual Studio 2015\Projects\NLayerAppV2" *.csproj -Recurse | Select-String -Pattern ".cs""" -Encoding default -CaseSensitive | %{ $_.line.Split('"')[1] }
// あるディクレクトリ内のすべてのcsファイルを抽出
$(Get-ChildItem -Path "C:\Users\koki\Documents\Visual Studio 2015\Projects\NLayerAppV2" *.cs -Recurse ).FullName
1行で書きたかったけど断念。
PowerShellでLINQしたいけど。出来そうで出来ない。多分できるけど頑張るほどでもない。
findNoManageCSFiles.ps1
$path = "パス名"
$a = Get-ChildItem -Path $path *.csproj -Recurse | Select-String -Pattern ".cs""" -Encoding default -CaseSensitive | %{ $_.line .Split('"' )[1 ] }
$b = $(Get-ChildItem -Path $path *.cs -Recurse ). FullName
foreach( $filename in $b )
{
$flg = $true;
foreach( $aname in $a )
{
if( $filename .Contains($aname ) )
{
$flg = $false;
break;
}
}
if( $flg )
{
Write-Output $filename
}
}