From 433f7dfd369d412e6aa82fd759d7010b7f6d3089 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Tue, 3 Dec 2024 03:58:24 +0700 Subject: [PATCH] Fix old .csproj fails to install Akka.Analyzers (#107) --- .gitignore | 2 -- src/Akka.Analyzers.Fixes/tools/install.ps1 | 22 +++++++++++++++++++ src/Akka.Analyzers.Fixes/tools/uninstall.ps1 | 22 +++++++++++++++++++ .../Akka.Analyzers.nuspec | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Akka.Analyzers.Fixes/tools/install.ps1 create mode 100644 src/Akka.Analyzers.Fixes/tools/uninstall.ps1 diff --git a/.gitignore b/.gitignore index 5291e15..343bbcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Custom -tools/ .nuget/ .dotnet/ .idea/ @@ -39,7 +38,6 @@ bld/ #FAKE .fake -tools/ #DocFx output _site/ diff --git a/src/Akka.Analyzers.Fixes/tools/install.ps1 b/src/Akka.Analyzers.Fixes/tools/install.ps1 new file mode 100644 index 0000000..8f55dd3 --- /dev/null +++ b/src/Akka.Analyzers.Fixes/tools/install.ps1 @@ -0,0 +1,22 @@ +param($installPath, $toolsPath, $package, $project) + +if($project.Object.SupportsPackageDependencyResolution) +{ + if($project.Object.SupportsPackageDependencyResolution()) + { + # Do not install analyzers via install.ps1, instead let the project system handle it. + return + } +} + +$analyzersPath = Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers\dotnet\roslyn3.11\cs" +if (Test-Path $analyzersPath) +{ + foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll) + { + if($project.Object.AnalyzerReferences) + { + $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) + } + } +} diff --git a/src/Akka.Analyzers.Fixes/tools/uninstall.ps1 b/src/Akka.Analyzers.Fixes/tools/uninstall.ps1 new file mode 100644 index 0000000..df1eeb3 --- /dev/null +++ b/src/Akka.Analyzers.Fixes/tools/uninstall.ps1 @@ -0,0 +1,22 @@ +param($installPath, $toolsPath, $package, $project) + +if($project.Object.SupportsPackageDependencyResolution) +{ + if($project.Object.SupportsPackageDependencyResolution()) + { + # Do not uninstall analyzers via uninstall.ps1, instead let the project system handle it. + return + } +} + +$analyzersPath = Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers\dotnet\roslyn3.11\cs" +if (Test-Path $analyzersPath) +{ + foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.dll) + { + if($project.Object.AnalyzerReferences) + { + $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) + } + } +} diff --git a/src/Akka.Analyzers.NuGet/Akka.Analyzers.nuspec b/src/Akka.Analyzers.NuGet/Akka.Analyzers.nuspec index 7fea31d..b73336d 100644 --- a/src/Akka.Analyzers.NuGet/Akka.Analyzers.nuspec +++ b/src/Akka.Analyzers.NuGet/Akka.Analyzers.nuspec @@ -19,6 +19,7 @@ +