0

We have a very large number of solutions spread across a wide number of repositories which do not always share a directory hierarchy in a way that makes it easy for us to update an .editorconfig such that it applies to all projects/solutions in the organization. We currently apply all of our code analysis configuration via an internal NuGet package and I was hoping we could include our organization-wide .editorconfig settings in this way as well?

I tried a quick experiment adding the following to a project to see if linked files would be honored (since we could simply add this to a props file we already have in the NuGet package), but it does not appear to be honored currently.

  <ItemGroup>
    <None Include="C:\SomeAlternatePath\ECTest\.editorconfig" Link=".editorconfig" />
  </ItemGroup>

是否有其他一些 MSBuild 属性或机制我们可以用来更好地促进这一点,而无需将重复文件写入每个解决方案/项目/存储库?

4

1 回答 1

1

是否有其他一些 MSBuild 属性或机制我们可以用来更好地促进这一点,而无需将重复文件写入每个解决方案/项目/存储库?

恐怕答案是否定的。因为该.editorconfig文件与 msbuild 或xx.csproj. 只有文件层次结构会影响配置文件的工作方式。更多细节请查看此文档

一些测试:

当我右键单击 project=>add将此文件添加到当前项目中时,会在:中.editorconfig添加一行。xx.csproj<None Include=".editorconfig"/>

如果我们设置indent_size = 32,它适用于当前项目。现在我们可以right-click that file=>Exclude from Project从当前项目系统中删除该文件。(此操作将删除<None Include=".editorconfig"/>xx.csproj 中的文件,但该文件仍在 xx.csproj 所在的同一文件夹中)

现在重新加载项目,设置(indent_size=32)仍然有效。所以很明显,如果我们把这个文件放在项目目录下,那么它就会生效,不管我们在项目文件( xx.csproj)中是否有关于它的定义。

建议:

根据您的描述,您所有的项目都使用同一个.editorconfig文件。由于此文件的工作范围受文件层次结构的影响,您可以通过以下方式减少一些无意义的工作:

1.将该文件放在解决方案文件夹中,它将适用于该解决方案文件夹下的所有项目

2.将该文件放在repos(C:\Users\xxx\source\repos) 文件夹中,它将适用于该文件夹下的所有解决方案和项目。

3.因此,如果您的大多数解决方案都在 path 下C:\somepath,请将该文件放在这里,该路径下的所有项目都将从中受益。关于优先file hierarchy请看这个

希望以上所有内容有所帮助:)

于 2019-10-25T10:15:03.643 回答