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

Add commandline switch to conditionally include project files based on msbuild conditions. #203

Open Priya91 opened 8 years ago

Priya91 commented 8 years ago

Is there a way to do this with .net compiler platform?

For ex, one of the project files in corefx:

 <ItemGroup Condition="'$(TargetsFreeBSD)'=='true'">
    <Compile Include="RuntimeInformation.FreeBSD.cs" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetsLinux)'=='true'">
    <Compile Include="RuntimeInformation.Linux.cs" />
  </ItemGroup>

Is there a way to format all files in the project, which may or may not be in compilation based on msbuild conditions.

cc @srivatsn @jaredpar @mellinoe

srivatsn commented 8 years ago

Not directly. MSBuild evaluates those conditions and drops those files before passing them to Roslyn. You'll have to parse the csproj files, identify all such conditions and recreate compilations with those constants set. I believe codeformatter already has some code for creating compilations for different sets of conditional constants taken from the commandline but I could be wrong.