dotnet / codeformatter

Tool that uses Roslyn to automatically rewrite the source to follow our coding styles
MIT License
1.24k stars 244 forks source link

allow CodeFormatter to run on Mono #245

Closed alexsorokoletov closed 8 years ago

alexsorokoletov commented 8 years ago

I would love to have a single source of truth for formatting C# code without any options to customize it.

Turns out there is a CodeFormatter project (thank you!) but it doesn't run well on Mono. During MVPSummit Hackathon with great help of @brettfo and guidance from @jaredpar we've been able to allow to run the CodeFormatter on mono with little changes.

How to run it on Mono then? First, install the tools sh init-tools.sh (downloads and unzips MSBuild for Mono, one could possibly symlink to current install instead of downloading, idea taken from Mono's MSBuild fork xplat-c9).

Restore NuGet packages and build the project: nuget restore src/CodeFormattter.sln && msbuild src/CodeFormatter.sln

Then run it: mono bin/CodeFormatter/Debug/CodeFormatter.exe ../codeformatter-test/test.rsp

Here's short video on overall process https://youtu.be/hLZ8nishxPo

Please let me know if there is a better way, I'm open for feedback. The pull request is related to #106

perlun commented 7 years ago

Any chance this could work with .NET Core nowadays? Or Mono only?

Petermarcu commented 7 years ago

@jaredpar , do you know offhand what dependencies may be blocking this on Core?

alexsorokoletov commented 7 years ago

@Petermarcu @perlun not Jared, but I believe it should work just fine on .NET Core. We would need to compile it against .NET Core and use MSBuild from .NET Core

jaredpar commented 7 years ago

@Petermarcu it could move to .Net core with a little bit of work as @alexsorokoletov suggested. I think there is a small amount of design work involved but probably 1-2 days of work.

perlun commented 7 years ago

Sounds great! Could anyone create a GH issue about it, so we can track progress (and discuss design ideas) there?

TimonVS commented 7 years ago

What's the status on this issue? After using Prettier and gofmt it's quite hard to go back to a programming language that doesn't have a formatter 😅

alexsorokoletov commented 7 years ago

Jared would be best person to outline the plan, but I could not agree more with Timon - after using formatter it's hard not to use it.

Basically, we have to migrate it to .net core and it will run anywhere where .net core runs.

alexsorokoletov commented 7 years ago

Here are few similar issues already opened:

I've quickly tried to migrate to .NET Core and there one thing that stops it: https://github.com/dotnet/corefx/issues/18452#issuecomment-305009282

Formatting project uses package Microsoft.CodeAnalysis.CSharp.Workspaces and it references the Microsoft.Composition package not available on .NET Core (should be migrated to System.Composition) and there a some changes related to that (MEF classes and namespaces mostly).