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

Support formatting ASP.NET vNext projects #87

Open conniey opened 9 years ago

conniey commented 9 years ago

I have an library that is written in C#, but I converted it to a .kproj (ASP.NET vNext library) so that my ASP.NET vNext website could also use its logic.

CodeFormatter skips over this project and doesn't format it. so I have to manually create a .csproj, add the .cs files, and run the formatter tool again.

.kproj Samples

jaredpar commented 9 years ago

@jasonmalinowski is there any way to load up ASP.Net vNext projects in Roslyn today? Right now the CodeFormatter just uses a MSBuildWorkspace. If there is an easy way to load this project type I'm sure it wouldn't take much work to get the code formatter to support it.

davidfowl commented 9 years ago

It's possible but not very nice right now. We're working on an API that will make this less sucky.

jaredpar commented 9 years ago

@davidfowl is there a GitHub issue I can track for this API? Once it's available I'd like to try it out here.

davidfowl commented 9 years ago

Not really, we're mostly layering things differently (some in NuGet, some in XRE) to make this possible. I'll update this thread when we get closer to having something useful.

danroth27 commented 9 years ago

@conniey Please also note that you don't have to convert your existing library project to a kproj to be able to reference it from your ASP.NET 5 app as long as you are ok with the app running on the full .NET Framework. You can reference csproj based projects from an ASP.NET 5 app. You would need to port your existing project only if you wanted to be able to run on .NET Core.

Petermarcu commented 9 years ago

@conniey @danroth27 We also plan on adding ASP.NET 5 as a target from a Portable Library so you wont need to have a seperate project file and multiple builds if you want to have you're shared logic applicable to multiple places.

conniey commented 9 years ago

@danroth27 The application that uses the library, I want to run on .NET Core. :) Thanks for the tip though.

shaunluttin commented 9 years ago

This issue also occurs with .xproj files. Here is my workaround:

  1. Add CodeFormatterWorkaround.csproj in your the directory.
  2. Then run codeformatter .\CodeFormatterWorkaround.csproj

This recursively formats all *.cs files without needing to specify them individually. Hooray!

CodeFormatterWorkaround.csproj contains only the following:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Compile Include="*.cs" />
    <Compile Include=".\**\*.cs" />
  </ItemGroup>
  <Target Name="Compile">
    <Csc Sources="@(Compile)"/>  
  </Target>
</Project>

See also: http://stackoverflow.com/questions/6914046/can-ms-build-include-all-library-project-code-files-without-specifying-them-indi