Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nuget refactorings and code fixes #1358

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,48 @@ jobs:
name: nuget_packages
path: src/${{ matrix.component.name }}.CodeFixes/bin/Release/*.*nupkg

build_refactorings:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: pre_build
runs-on: ubuntu-22.04
env:
Version: ${{ needs.pre_build.outputs.version }}
defaults:
run:
working-directory: src/Refactorings
steps:
- uses: actions/checkout@v3
- run: dotnet restore --force /p:RoslynVersion=roslyn3.8
- run: dotnet build --no-restore /p:RoslynatorRefactoringsNuGet=true /p:RoslynVersion=roslyn3.8
- run: dotnet restore --force /p:RoslynVersion=roslyn4.7
- run: dotnet build --no-restore /p:RoslynatorRefactoringsNuGet=true /p:RoslynVersion=roslyn4.7
- run: dotnet pack --no-build
- uses: actions/upload-artifact@v3
with:
name: nuget_packages
path: src/Refactorings/bin/Release/*.*nupkg

build_code_fixes:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: pre_build
runs-on: ubuntu-22.04
env:
Version: ${{ needs.pre_build.outputs.version }}
defaults:
run:
working-directory: src/CodeFixes
steps:
- uses: actions/checkout@v3
- run: dotnet restore --force /p:RoslynVersion=roslyn3.8
- run: dotnet build --no-restore /p:RoslynatorCodeFixesNuGet=true /p:RoslynVersion=roslyn3.8
- run: dotnet restore --force /p:RoslynVersion=roslyn4.7
- run: dotnet build --no-restore /p:RoslynatorCodeFixesNuGet=true /p:RoslynVersion=roslyn4.7
- run: dotnet pack --no-build
- uses: actions/upload-artifact@v3
with:
name: nuget_packages
path: src/CodeFixes/bin/Release/*.*nupkg

build_vs_extension:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: pre_build
Expand Down Expand Up @@ -242,7 +284,7 @@ jobs:
path: src/CommandLine/bin/Release/*.*nupkg

publish_nuget_packages:
needs: [ build_core_and_testing, build_analyzers ]
needs: [ build_core_and_testing, build_analyzers, build_refactorings, build_code_fixes ]
runs-on: ubuntu-22.04
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
steps:
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Publish NuGet packages that provide [refactorings](https://www.nuget.org/packages/roslynator.refactorings) and [code fixes for compiler diagnostics](https://www.nuget.org/packages/roslynator.codefixes) ([PR](https://github.com/dotnet/roslynator/pull/1358))
- These packages are recommended to be used in an environment where Roslynator IDE extension cannot be used, e.g. VS Code + C# Dev Kit (see related [issue](https://github.com/dotnet/vscode-csharp/issues/6790))

### Fixed

- Fix analyzer [RCS1055](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1055) ([PR](https://github.com/dotnet/roslynator/pull/1361))
Expand Down
9 changes: 7 additions & 2 deletions src/CodeFixes/CodeFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(RoslynVersion)' != ''">
<BaseOutputPath>bin\$(RoslynVersion)\</BaseOutputPath>
</PropertyGroup>

<PropertyGroup>
<Version>$(RoslynatorVersion)</Version>
<AssemblyName>Roslynator.CSharp.CodeFixes</AssemblyName>
<RootNamespace>Roslynator.CSharp.CodeFixes</RootNamespace>
<NuspecFile>Roslynator.CodeFixes.nuspec</NuspecFile>
<NuspecProperties>configuration=$(Configuration)</NuspecProperties>
<IsPackable>false</IsPackable>
<NuspecProperties>configuration=$(Configuration);version=$(RoslynatorPackageVersion)</NuspecProperties>
<IsPackable>true</IsPackable>
<IncludeSymbols>false</IncludeSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 8 additions & 5 deletions src/CodeFixes/Roslynator.CodeFixes.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
<projectUrl>https://github.com/dotnet/roslynator</projectUrl>
<icon>icon.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A collection of code fixes for C# compiler diagnostics (CS....), powered by Roslyn.</description>
<summary>A collection of code fixes for C# compiler diagnostics (CS....), powered by Roslyn.</summary>
<copyright>Copyright (c) 2016-2023 Josef Pihrt</copyright>
<tags>Roslyn Analyzer Refactoring Productivity CodeAnalysis C# CSharp</tags>
<description>A collection of code fixes for C# compiler diagnostics, powered by Roslyn.</description>
<summary>A collection of code fixes for C# compiler diagnostics, powered by Roslyn.</summary>
<copyright>Copyright (c) 2016-2024 Josef Pihrt</copyright>
<tags>Roslyn Refactoring Productivity CodeAnalysis C# CSharp</tags>
<developmentDependency>true</developmentDependency>
<repository type="git" url="https://github.com/dotnet/roslynator.git" />
<readme>docs\README.md</readme>
</metadata>
<files>
<file src="bin\$Configuration$\netstandard1.3\Roslynator*.dll" target="analyzers\dotnet\cs" />
<file src="bin\roslyn3.8\$Configuration$\netstandard2.0\Roslynator*.dll" target="analyzers/dotnet/roslyn3.8/cs" />
<file src="bin\roslyn4.7\$Configuration$\netstandard2.0\Roslynator*.dll" target="analyzers/dotnet/roslyn4.7/cs" />
<file src="tools\*.ps1" target="tools\" />
<file src="..\..\images\roslynator-logo-small.png" target="icon.png" />
<file src="docs\NuGetReadme.md" target="docs\README.md" />
</files>
</package>
33 changes: 33 additions & 0 deletions src/CodeFixes/docs/NuGetReadme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Roslynator.CodeFixes

A collection [code fixes](https://josefpihrt.github.io/docs/roslynator/fixes) for C# compiler diagnostics, powered by [Roslyn](https://github.com/dotnet/roslyn).

This package is recommended to be used in an enviroment where Roslynator IDE extensions cannot be used, e.g. VS Code + C# Dev Kit.
Otherwise, do not use this package and use IDE extension which has the same functionality.

## Requirements

* Visual Studio 2022
* VS Code with [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) extension 1.21.13 or higher
* Roslyn 3.8.0 or higher (when used directly, not as a part of IDE)

## Usage

* Add package to your project:
```shell
dotnet add package roslynator.codefixes
```

* Use EditorConfig to [configure](https://josefpihrt.github.io/docs/roslynator/configuration) analyzers.

## Feedback

* File an issue on [GitHub](https://github.com/dotnet/roslynator/issues/new)
* Follow on [Twitter](https://twitter.com/roslynator)

## Related Products

* [Roslynator for Visual Studio 2022](https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2022)
* [Roslynator for VS Code](https://marketplace.visualstudio.com/items?itemName=josefpihrt-vscode.roslynator)
* [Roslynator Command-line Tool](https://www.nuget.org/packages/Roslynator.DotNet.Cli)
* [Roslynator Testing Framework](https://www.nuget.org/packages/Roslynator.Testing.CSharp.Xunit)
8 changes: 8 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
<RoslynatorDllPrefix>Roslynator_Formatting_Analyzers_</RoslynatorDllPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(RoslynatorRefactoringsNuGet)' == true">
<RoslynatorDllPrefix>Roslynator_Refactorings_</RoslynatorDllPrefix>
</PropertyGroup>

<PropertyGroup Condition="'$(RoslynatorCodeFixesNuGet)' == true">
<RoslynatorDllPrefix>Roslynator_CodeFixes_</RoslynatorDllPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="roslynator.analyzers" Version="$(RoslynatorAnalyzersPackageReferenceVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
19 changes: 12 additions & 7 deletions src/Refactorings/Refactorings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(RoslynVersion)' != ''">
<BaseOutputPath>bin\$(RoslynVersion)\</BaseOutputPath>
</PropertyGroup>

<PropertyGroup>
<Version>$(RoslynatorVersion)</Version>
<AssemblyName>Roslynator.CSharp.Refactorings</AssemblyName>
<RootNamespace>Roslynator.CSharp.Refactorings</RootNamespace>
<NuspecFile>Roslynator.Refactorings.nuspec</NuspecFile>
<NuspecProperties>configuration=$(Configuration);version=$(RoslynatorPackageVersion)</NuspecProperties>
<IsPackable>true</IsPackable>
<IncludeSymbols>false</IncludeSymbols>
</PropertyGroup>

<PropertyGroup>
<IsPackable>false</IsPackable>
<Company></Company>
<Description></Description>
</PropertyGroup>
<ItemGroup>
<None Remove="tools\install.ps1" />
<None Remove="tools\uninstall.ps1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(RoslynatorRoslynAnalyzersVersion)">
Expand All @@ -24,8 +31,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(RoslynatorRoslynVersion)" />
</ItemGroup>



<ItemGroup>
<ProjectReference Include="..\Workspaces.Common\Workspaces.Common.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
Expand Down
27 changes: 27 additions & 0 deletions src/Refactorings/Roslynator.Refactorings.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.8">
<id>Roslynator.Refactorings</id>
<version>$version$</version>
<authors>Josef Pihrt</authors>
<owners>Josef Pihrt</owners>
<license type="expression">Apache-2.0</license>
<projectUrl>https://github.com/dotnet/roslynator</projectUrl>
<icon>icon.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A collection of 200+ refactorings for C#, powered by Roslyn.</description>
<summary>A collection of 200+ refactorings for C#, powered by Roslyn.</summary>
<copyright>Copyright (c) 2016-2024 Josef Pihrt</copyright>
<tags>Roslyn Refactoring Productivity CodeAnalysis C# CSharp</tags>
<developmentDependency>true</developmentDependency>
<repository type="git" url="https://github.com/dotnet/roslynator.git" />
<readme>docs\README.md</readme>
</metadata>
<files>
<file src="bin\roslyn3.8\$Configuration$\netstandard2.0\Roslynator*.dll" target="analyzers/dotnet/roslyn3.8/cs" />
<file src="bin\roslyn4.7\$Configuration$\netstandard2.0\Roslynator*.dll" target="analyzers/dotnet/roslyn4.7/cs" />
<file src="tools\*.ps1" target="tools\" />
<file src="..\..\images\roslynator-logo-small.png" target="icon.png" />
<file src="docs\NuGetReadme.md" target="docs\README.md" />
</files>
</package>
33 changes: 33 additions & 0 deletions src/Refactorings/docs/NuGetReadme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Roslynator.Refactorings

A collection of 200+ [refactorings](https://josefpihrt.github.io/docs/roslynator/refactorings) for C#, powered by [Roslyn](https://github.com/dotnet/roslyn).

This package is recommended to be used in an enviroment where Roslynator IDE extensions cannot be used, e.g. VS Code + C# Dev Kit.
Otherwise, do not use this package and use IDE extension which has the same functionality.

## Requirements

* Visual Studio 2022
* VS Code with [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) extension 1.21.13 or higher
* Roslyn 3.8.0 or higher (when used directly, not as a part of IDE)

## Usage

* Add package to your project:
```shell
dotnet add package roslynator.refactorings
```

* Use EditorConfig to [configure](https://josefpihrt.github.io/docs/roslynator/configuration) analyzers.

## Feedback

* File an issue on [GitHub](https://github.com/dotnet/roslynator/issues/new)
* Follow on [Twitter](https://twitter.com/roslynator)

## Related Products

* [Roslynator for Visual Studio 2022](https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2022)
* [Roslynator for VS Code](https://marketplace.visualstudio.com/items?itemName=josefpihrt-vscode.roslynator)
* [Roslynator Command-line Tool](https://www.nuget.org/packages/Roslynator.DotNet.Cli)
* [Roslynator Testing Framework](https://www.nuget.org/packages/Roslynator.Testing.CSharp.Xunit)
49 changes: 49 additions & 0 deletions src/Refactorings/tools/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
param($installPath, $toolsPath, $package, $project)

$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve

foreach($analyzersPath in $analyzersPaths)
{
# Install the language agnostic analyzers.
if (Test-Path $analyzersPath)
{
foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll)
{
if($project.Object.AnalyzerReferences)
{
$project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
}
}
}
}

# $project.Type gives the language name like (C# or VB.NET)
$languageFolder = ""
if($project.Type -eq "C#")
{
$languageFolder = "cs"
}
if($project.Type -eq "VB.NET")
{
$languageFolder = "vb"
}
if($languageFolder -eq "")
{
return
}

foreach($analyzersPath in $analyzersPaths)
{
# Install language specific analyzers.
$languageAnalyzersPath = join-path $analyzersPath $languageFolder
if (Test-Path $languageAnalyzersPath)
{
foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll)
{
if($project.Object.AnalyzerReferences)
{
$project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
}
}
}
}
56 changes: 56 additions & 0 deletions src/Refactorings/tools/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
param($installPath, $toolsPath, $package, $project)

$analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve

foreach($analyzersPath in $analyzersPaths)
{
# Uninstall the language agnostic analyzers.
if (Test-Path $analyzersPath)
{
foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll)
{
if($project.Object.AnalyzerReferences)
{
$project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
}
}
}
}

# $project.Type gives the language name like (C# or VB.NET)
$languageFolder = ""
if($project.Type -eq "C#")
{
$languageFolder = "cs"
}
if($project.Type -eq "VB.NET")
{
$languageFolder = "vb"
}
if($languageFolder -eq "")
{
return
}

foreach($analyzersPath in $analyzersPaths)
{
# Uninstall language specific analyzers.
$languageAnalyzersPath = join-path $analyzersPath $languageFolder
if (Test-Path $languageAnalyzersPath)
{
foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll)
{
if($project.Object.AnalyzerReferences)
{
try
{
$project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
}
catch
{

}
}
}
}
}