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

Added custom build targets to nuget package to simplify setting item group for settings file #1581

Merged
merged 3 commits into from
Oct 16, 2015

Conversation

oatkins
Copy link
Contributor

@oatkins oatkins commented Sep 30, 2015

Added custom .targets and .props file with code to make it easy to set the item group for stylecop.json to StyleCopSettings. Include StyleCopSettings in AdditionalFileItemNames group.

I wouldn't be surprised if you've though of this already... and have a good reason why we shouldn't include it. But maybe it's just that nobody got around to it ;-)

@sharwell
Copy link
Member

The primary reason this wasn't addressed yet is no one took the time to do it.

That said, I do have a few concerns and I'm not sure what the best approach is.

  1. This approach only works for users with standard project files. DNX users working with the new file-system projects would need a different solution.
  2. This change is a workaround for an ongoing Roslyn limitation; see Solution.AddAdditionalDocument does not add a new file with AdditionalFiles item type dotnet/roslyn#4655, Analyzers should be able to specify additional files without using MSBuild dotnet/roslyn#5096, Cannot set build action to AdditionalFiles in Visual Studio dotnet/roslyn#5104. Depending on the final resolution of these issues, our approach may change. If we implement the solution proposed in this pull request, users may be forced to change the way stylecop.json is added a second time if we adopt some other solution provided by the infrastructure.

If we could eliminate the requirement that users manually set the build type of stylecop.json to StyleCopSettings, we would somewhat address the second concern by automating the first change. For example, we could have a target automatically added to the build which identifies any files named stylecop.json with the build action None and automatically adds them to the set of additional files.

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to occur unconditionally, since command line builds still need to be aware of the stylecop.json file in order to produce accurate results.

@oatkins oatkins force-pushed the stylecopsettings-item-name branch from 638f79a to 31cdb37 Compare September 30, 2015 17:42
@oatkins
Copy link
Contributor Author

oatkins commented Sep 30, 2015

@sharwell Thanks. Good point about the condition being unwanted.

DNX users... would need a different solution.

Yup, I saw that discussion. It didn't seem to negate the value of making this work for MSBuild/VS projects though.

This change is a workaround for an ongoing Roslyn limitation.

Maybe so, though my suspicion is that they intended for items to be added to the AdditionalFiles group indirectly, and that this is the reason why "AdditionalFiles" doesn't show up on the VS menu.

We could have a target automatically added to the build which identifies any files named stylecop.json with the build action None and automatically adds them to the set of additional files.

It would be really nice if users could get settings working without having to make changes to the project file directly. The approach you describe would achieve that too. I'd be happy to change the diff to make it work that way instead if you think that's better.

@sharwell
Copy link
Member

So it seems we can use the following StyleCop.Analyzers.targets file and omit the .props file completely. This implementation would not require users to perform any additional steps to enable the stylecop.json settings file after executing the code fix which adds it to a project (aside from possibly needing to reload the project; I haven't tested this specific case).

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="InjectStyleCopSettings"
          BeforeTargets="CoreCompile">
    <ItemGroup>
      <StyleCopSettings Include="@(None)"
                        Condition="'%(Filename)%(Extension)' == 'stylecop.json'"/>
      <AdditionalFiles Include="%(StyleCopSettings.Identity)" />
    </ItemGroup>
  </Target>
</Project>

…t the item group for stylecop.json to StyleCopSettings. Include StyleCopSettings in AdditionalFileItemNames group.
@oatkins oatkins force-pushed the stylecopsettings-item-name branch from 4d6009f to 5e4d166 Compare October 15, 2015 17:09
@codecov-io
Copy link

Current coverage is 79.77%

Merging #1581 into master will decrease coverage by -0.01% as of 5bf2687

@@            master   #1581   diff @@
======================================
  Files          531     531       
  Stmts        31679   31679       
  Branches      8871    8871       
  Methods                          
======================================
- Hit          25275   25271     -4
- Partial       5153    5157     +4
  Missed        1251    1251       

Review entire Coverage Diff as of 5bf2687

Powered by Codecov. Updated on successful CI builds.

@sharwell sharwell added this to the 1.0.0 Beta 14 milestone Oct 16, 2015
@sharwell sharwell self-assigned this Oct 16, 2015
@sharwell
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants