Skip to content

Commit

Permalink
Add NuGet Package (#9)
Browse files Browse the repository at this point in the history
* Add Package Project

* Add Release action

* Fix README

* Fix package ID
  • Loading branch information
Scogun authored May 30, 2022
1 parent 881228e commit 8ec9000
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 5 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build, Test and Release

on:
release:
types: published

jobs:
test:

uses: ./.github/workflows/tests.yml

release:

needs: test

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
name: Setup .Net
with:
dotnet-version: 6.x.x
- name: Restore dependencies
run: dotnet restore
- name: Release
run: dotnet build --no-restore -c Release -p:Version=${{ github.event.release.tag_name }}.0
- name: Push
run: dotnet nuget push ./package/AutoMapper.Analyzers.Common.Package/bin/Release/AutoMapper.Extensions.Analyzers.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build and Test
on:
pull_request:
branches: main
workflow_call:

jobs:
build-and-test:
Expand Down
10 changes: 10 additions & 0 deletions AutoMapper.Analyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMapper.Analyzers.Common.Package", "package\AutoMapper.Analyzers.Common.Package\AutoMapper.Analyzers.Common.Package.csproj", "{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,14 @@ Global
{4FC11BE6-9A0D-4147-A968-9D2B508D25D5}.Release|Any CPU.Build.0 = Release|Any CPU
{4FC11BE6-9A0D-4147-A968-9D2B508D25D5}.Release|x86.ActiveCfg = Release|Any CPU
{4FC11BE6-9A0D-4147-A968-9D2B508D25D5}.Release|x86.Build.0 = Release|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Debug|x86.ActiveCfg = Debug|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Debug|x86.Build.0 = Debug|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Release|Any CPU.Build.0 = Release|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Release|x86.ActiveCfg = Release|Any CPU
{6BE5CCD5-652C-410F-8A37-3E046C3F62DF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
1. [Overview](#overview)
2. [Structure](#structure)
1. [Currently Available](#currently-available)
2. [In Progress](#in-progress)
3. [Code Smells](#code-smells)
4. [Installation](#installation)
1. [NuGet package](#nuget-package)
Expand All @@ -23,10 +22,9 @@ The main reason to write this VS Extension and NuGet package is that developers
The project already contains:
1. [AutoMapper.Analyzers.Common](src/AutoMapper.Analyzers.Common/AutoMapper.Analyzers.Common.csproj) - common AutoMapper Analyzers
2. [AutoMapper.Analyzers.Common.CodeFixes](src/AutoMapper.Analyzers.Common.CodeFixes/AutoMapper.Analyzers.Common.CodeFixes.csproj) - common fixes for raised AutoMapper Analyzers diagnostics
3. [AutoMapper.Analyzers.Common.Tests](tests/AutoMapper.Analyzers.Common.Tests/AutoMapper.Analyzers.Common.Tests.csproj) - tests for common AutoMapper Analyzers
4. [AutoMapper.Analyzers.Vsix](package/AutoMapper.Analyzers.Vsix/AutoMapper.Analyzers.Vsix.csproj) - project to create VS Extension package
##### In Progress
1. AutoMapper.Analyzers.Common.Package - project for building and publishing the NuGet package
3. [AutoMapper.Analyzers.Common.Package](package/AutoMapper.Analyzers.Common.Package/AutoMapper.Analyzers.Common.Package.csproj) - project for building and publishing the NuGet package
4. [AutoMapper.Analyzers.Common.Tests](tests/AutoMapper.Analyzers.Common.Tests/AutoMapper.Analyzers.Common.Tests.csproj) - tests for common AutoMapper Analyzers
5. [AutoMapper.Analyzers.Vsix](package/AutoMapper.Analyzers.Vsix/AutoMapper.Analyzers.Vsix.csproj) - project to create VS Extension package

## Code Smells
<table>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
<PackageId>AutoMapper.Extensions.Analyzers</PackageId>
<Authors>Sergey Antonov</Authors>
<PackageProjectUrl>https://github.com/Scogun/AutoMapper.Analyzers</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/Scogun/AutoMapper.Analyzers/blob/main/LICENSE</PackageLicenseUrl>
<PackageIcon>Logo.png</PackageIcon>
<PackageIconUrl />
<RepositoryUrl>https://github.com/Scogun/AutoMapper.Analyzers</RepositoryUrl>
<PackageTags>AutoMapper, analyzers</PackageTags>
<NoPackageAnalysis>true</NoPackageAnalysis>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_OutputAnalyzers</TargetsForTfmSpecificContentInPackage>
<Company>UCASoft</Company>
<Product>AutoMapper Analyzers</Product>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AutoMapper.Analyzers.Common.CodeFixes\AutoMapper.Analyzers.Common.CodeFixes.csproj" />
<ProjectReference Include="..\..\src\AutoMapper.Analyzers.Common\AutoMapper.Analyzers.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\Logo.png" Pack="true" PackagePath="" />
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="" />
</ItemGroup>


<Target Name="_OutputAnalyzers">
<ItemGroup>
<TfmSpecificPackageFile Include="$(OutputPath)\AutoMapper.Analyzers.Common.dll" PackagePath="analyzers/dotnet/cs" />
<TfmSpecificPackageFile Include="$(OutputPath)\AutoMapper.Analyzers.Common.CodeFixes.dll" PackagePath="analyzers/dotnet/cs" />
</ItemGroup>
</Target>

</Project>
58 changes: 58 additions & 0 deletions package/AutoMapper.Analyzers.Common.Package/tools/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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
}
}

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

foreach($analyzersPath in $analyzersPaths)
{
if (Test-Path $analyzersPath)
{
# Install the language agnostic analyzers.
foreach ($analyzerFilePath in Get-ChildItem -Path "$analyzersPath\*.dll" -Exclude *.resources.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 -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll)
{
if($project.Object.AnalyzerReferences)
{
$project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName)
}
}
}
}
65 changes: 65 additions & 0 deletions package/AutoMapper.Analyzers.Common.Package/tools/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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
}
}

$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 -Path "$analyzersPath\*.dll" -Exclude *.resources.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 -Path "$languageAnalyzersPath\*.dll" -Exclude *.resources.dll)
{
if($project.Object.AnalyzerReferences)
{
try
{
$project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName)
}
catch
{

}
}
}
}
}

0 comments on commit 8ec9000

Please sign in to comment.