-
Notifications
You must be signed in to change notification settings - Fork 510
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
Added custom build targets to nuget package to simplify setting item group for settings file #1581
Conversation
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.
If we could eliminate the requirement that users manually set the build type of stylecop.json to |
<?xml version="1.0" encoding="utf-8" ?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'"> |
There was a problem hiding this comment.
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.
638f79a
to
31cdb37
Compare
@sharwell Thanks. Good point about the condition being unwanted.
Yup, I saw that discussion. It didn't seem to negate the value of making this work for MSBuild/VS projects though.
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.
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. |
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.
4d6009f
to
5e4d166
Compare
Current coverage is
|
👍 |
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 ;-)