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 package with build tasks to format on build #200

Merged
merged 13 commits into from
May 24, 2021
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
11 changes: 9 additions & 2 deletions .github/workflows/nuget_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jobs:
needs: test
steps:
- uses: actions/checkout@v2
- name: publish on version change
- name: publish csharpier on version change
id: publish_nuget
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: Src/CSharpier/CSharpier.csproj
TAG_FORMAT: "*"
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
- name: publish csharpier.msbuild on version change
id: publish_nuget
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj
TAG_FORMAT: "*"
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
8 changes: 8 additions & 0 deletions CSharpier.Targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<Version>0.9.2</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
</Project>
21 changes: 11 additions & 10 deletions CSharpier.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpier.Playground", "Src\CSharpier.Playground\CSharpier.Playground.csproj", "{E7F03E73-82C7-4DB2-AF20-F25C45231A72}"
EndProject
Expand All @@ -21,26 +21,27 @@ EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{176BB0EA-B72B-4ACA-82AE-C16A732BE023}"
ProjectSection(SolutionItems) = preProject
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
.github\workflows\nuget_publish.yml = .github\workflows\nuget_publish.yml
.github\workflows\playground_publish.yml = .github\workflows\playground_publish.yml
.github\workflows\validatePR.yml = .github\workflows\validatePR.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{62DCCDB3-45D3-4236-B34A-E01618028BFE}"
ProjectSection(SolutionItems) = preProject
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
Scripts/ChangeLog.ps1 = Scripts/ChangeLog.ps1
Scripts/UpdateForkedRepos.ps1 = Scripts/UpdateForkedRepos.ps1
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
Scripts/ChangeLog.ps1 = Scripts/ChangeLog.ps1
Scripts/UpdateForkedRepos.ps1 = Scripts/UpdateForkedRepos.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{7C99AEA7-E608-40B5-9B2E-353B6E4C9DBE}"
ProjectSection(SolutionItems) = preProject
Docs/EditorsAndCICD.md = Docs/EditorsAndCICD.md
Docs/Configuration.md = Docs/Configuration.md
Docs/CLI.md = Docs/CLI.md
Docs/Ignore.md = Docs/Ignore.md
Docs/EditorsAndCICD.md = Docs/EditorsAndCICD.md
Docs/Configuration.md = Docs/Configuration.md
Docs/CLI.md = Docs/CLI.md
Docs/Ignore.md = Docs/Ignore.md
Docs\MSBuild.md = Docs\MSBuild.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpier.Benchmarks", "Src\CSharpier.Benchmarks\CSharpier.Benchmarks.csproj", "{A338903F-69AD-4950-B827-8EE75F98B620}"
Expand Down
16 changes: 16 additions & 0 deletions Docs/MSBuild.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### MSBuild Package
CSharpier can be run when a package is built by installing the CSharpier.MSBuild nuget package
```console
Install-Package CSharpier.MSBuild
```

By default this will
- In Debug - on build will run `dotnet csharpier` in the project folder to format all files in the project.
- In Release - on build will run `dotnet csharpier --check` in the project folder to validate that all files in the project have already been formatted.

You can control when `--check` is used with the following Property
```xml
<PropertyGroup>
<CSharpier_Check>false</CSharpier_Check>
</PropertyGroup>
```
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,31 @@ public class ClassName
```

## Installation

```console
dotnet tool install -g csharpier
```

## Basic Usage
### Basic Usage
Run csharpier from the directory you wish to format.
```console
dotnet csharpier
```

### MsBuild Package
If you prefer to have csharpier run when a project is built, you can use the CSharpier.MSBuild nuget package
```console
Install-Package CShariper.MSBuild
```

## Documentation
[Command Line Interface](Docs/CLI.md)
[Configuration File](Docs/Configure.md)
[Editors and CI/CD](Docs/EditorsAndCICD.md)
[Ignoring Files](Docs/Ignore.md)
[ChangeLog](CHANGELOG.md)
[ChangeLog](CHANGELOG.md)
[MSBuild Package](Docs/MSBuild.md)


## Contributing
See [Development Readme](CONTRIBUTING.md)
Expand Down
22 changes: 22 additions & 0 deletions Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../CSharpier.Targets"/>
<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
<PackageId>CSharpier.MsBuild</PackageId>
<CSharpierOutputDir>../CSharpier/bin/$(Configuration)/net5.0</CSharpierOutputDir>
</PropertyGroup>

<!--
Note: There is no <ProjectReference /> here because that would cause msbuild to
make it a dependency in the output package, which causes all sorts of issues as
CSharpier is a net5.0 project with <PackAsTool> and this is neither.
-->
<Target Name="BuildCSharpier" BeforeTargets="Build">
<Exec command="dotnet build -c $(Configuration)" WorkingDirectory="../CSharpier" />
</Target>

<ItemGroup>
<Content Include="build/*" PackagePath="build/" />
<Content Include="$(CSharpierOutputDir)/**" PackagePath="tools/csharpier" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Src/CSharpier.MsBuild/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
You can test this by doing
`dotnet pack -o publish`
Then add a nuget source pointing to that folder and install the nuget package into a project
10 changes: 10 additions & 0 deletions Src/CSharpier.MsBuild/build/CSharpier.MsBuild.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<!-- Setting default value here, so it can be overwritten by caller -->
<CSharpier_Check>false</CSharpier_Check>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<CSharpier_Check>true</CSharpier_Check>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>
<PropertyGroup>
<CSharpierDllPath>$(MSBuildThisFileDirectory)../tools/csharpier/dotnet-csharpier.dll</CSharpierDllPath>
<CSharpierArgs Condition="$(CSharpier_Check)">$(CSharpierArgs) --check</CSharpierArgs>
</PropertyGroup>

<!-- Target invokes the copy of csharpier from this package on the current project -->
<Target
Name="CSharpierFormat"
BeforeTargets="Build">
<Exec Command="dotnet $(CSharpierDllPath) $(CSharpierArgs) $(MSBuildProjectDirectory)" />
</Target>
</Project>
34 changes: 15 additions & 19 deletions Src/CSharpier/CSharpier.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../../CSharpier.Targets"/>
<PropertyGroup>
<OutputType>Exe</OutputType>
<PackageId>CSharpier</PackageId>
<AssemblyName>dotnet-csharpier</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>CSharpier</PackageId>
<AssemblyName>dotnet-csharpier</AssemblyName>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>CSharpier</RootNamespace>
<PackAsTool>true</PackAsTool>
<Version>0.9.3</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackAsTool>true</PackAsTool>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ignore" Version="0.1.42" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.29" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.29" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="UTF.Unknown" Version="2.3.0" />
<PackageReference Include="YamlDotNet" Version="11.1.1" />
<PackageReference Include="Ignore" Version="0.1.42" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.29" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.29" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="UTF.Unknown" Version="2.3.0" />
<PackageReference Include="YamlDotNet" Version="11.1.1" />
</ItemGroup>

</Project>