问题
I have prepared my .editorconfig
file which I want to use on multiple Git repositories. Each repository holds a Visual Studio solution (C#). My first thought was to put the .editorconfig
file in its own repository and then include it in all "solution repositories" as submodule. The problem however: The submodule will be in a subfolder. The contained .editorconfig
will thus not be applied to the whole project/solution (but only to the subfolder and its children). It seems to me that I cannot specify a path to my solution-wide .editorconfig
in the solution configuration file (.sln
), either.
What is the best approach to actually share a single .editorconfig
file between multiple Git repositories? The .editorconfig
file still needs to be version controlled (and thus shared between users), ie. no local editorconfig configuration.
回答1:
I found a solution myself using a shared repository as submodule as I wanted: It's a symbolic link!
For example, if your submodule is called Global
, go into the root of your solution and create a symbolic link to the real file in subfolder Global
via:
mklink .editorconfig .\Global\.editorconfig
This link can be committed and pushed like any other file. Gitea (which I am using as server) even shows a small arrow as overlay for the file symbol. Apparantly it knows that it is just a symbolic link. When I clone this repository on a Windows machine, the symbolic link works as expected. Maybe it even works on *nix systems; I did not try though.
I draw back of this solution: VS2017 (15.8.2) does not pick up changes immediately. One has to close and re-open the solution. If you are using a real .editorconfig file changes are detected immediately since 15.8 Preview 3.
Edit: We decided not to commit the symbolic link to Git because it once screwed by Gitea (might have been a bug) and because we have non-Windows development systems. Instead we have a 'post clone script' in combination with a conditional error in our project files <Error Condition="!Exists('$(SolutionDir).editorconfig')" Text=".editorconfig is missing. Please run $(SolutionDir)_post_clone_script.bat first." />
.
来源:https://stackoverflow.com/questions/52186841/editorconfig-in-shared-git-repository