Hi.
What if I want to use the same stylecop.json across all projects in the solution?
I've tried to make solution folder, put there stylecop.json and add it as a link to every project, but quick action "Add file header" still uses default style cop settings (I've changed company name).
(Sorry, I can't add "question" tag to the issue)
I should read docs more attentively. It was enabling stlycop.json issue.
@Dennis-Petrov So what actually you did? Copy stylecop.json to each project but change BuildAction to AdditionalFiles?
@kkorus You don't have to copy the file around. You can use the same file in multiple projects in your solution as long as the build action is set to AdditionalFiles.
@sharwell Ok so I need to link one file to multiple projects and change build action of each link to AdditionalFiles?
@kkorus Yes, like this:
<AdditionalFiles Include="{relativePathTo}\stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
@kkorus, in addition to @sharwell's answer.
Finally I ended up with SharedProjectSettings.proj file (there are 250+ csproj in my sources). It's MSBuild project file, and it includes stylecop.json, as well as ruleset and other msbuild stuff:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\Shared\StyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\Shared\stylecop.json" Link="Properties\stylecop.json" />
</ItemGroup>
<!-- ... -->
</Project>
Particular csproj imports SharedProjectSettings.proj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<Import Project="..\..\Shared\SharedProjectSettings.proj" />
<!-- ... -->
</Project>
@Dennis-Petrov Where do you keep SharedProjectSettings.proj ?
Here's my repo folders structure:
Root
Source
Feature1
Project1
Project2
Feature2
Project3
Project4
...
Shared
SharedProjectSettings.proj is located in Shared folder with other shared files.
馃摑 If you use the name Directory.Build.props and place the file in a parent directory (e.g. Root/Source instead of Root/Source/Shared), the file will be automatically imported by MSBuild, removing the need to manually reference it. This is how dotnet/roslyn-sdk includes the file for everything below src/Tools/Microsoft.CodeAnalysis.Testing without needing to update all of the individual project files:
https://github.com/dotnet/roslyn-sdk/blob/3e94c5fe1ee981a885c34e2e39383bc4420f2557/src/Tools/Microsoft.CodeAnalysis.Testing/Directory.Build.props#L50-L60
@sharwell, cool, didn't know this. The problem is that not all of my projects are netstandard/netcoreapp - there are number of "full" .NET projects, and they import their own settings. Maybe, conditions will help me...
@sharwell @Dennis-Petrov Thanks guys for help! 馃帀馃帀馃帀馃帀
Most helpful comment
馃摑 If you use the name Directory.Build.props and place the file in a parent directory (e.g. Root/Source instead of Root/Source/Shared), the file will be automatically imported by MSBuild, removing the need to manually reference it. This is how dotnet/roslyn-sdk includes the file for everything below src/Tools/Microsoft.CodeAnalysis.Testing without needing to update all of the individual project files:
https://github.com/dotnet/roslyn-sdk/blob/3e94c5fe1ee981a885c34e2e39383bc4420f2557/src/Tools/Microsoft.CodeAnalysis.Testing/Directory.Build.props#L50-L60