0

I'm working on several projects across different Git repositories, and I want to maintain a consistent ReSharper configuration across all of them. To achieve this, I'm considering storing the ReSharper configuration files in a common Git repository and syncing them with other repositories.

Is there a way to set up my environment so that I can:

  1. Store ReSharper configuration files in a central Git repository.

  2. Sync these configuration files with multiple other Git repositories.

Ideally, I would like a solution that automatically updates the configuration files in the other repositories whenever changes are made in the central repository. Without git submodules.

1 Answer 1

0

There is no super convenient way, but let me describe how we solved this in my previous team.

First of all, we have one Git repo (let's call it CodeStyle) containing all settings that shall be shared:

CreateSymbolicLinkForEditorconfig.ps1
MyCompany.DotSettings
.editorconfig
ReSpeller/de.aff
ReSpeller/de.dic

Every developer will clone this repo, e.g. into C:\source\CodeStyle.

Now we have different apps, all living in their repository:

  • MyApp1
  • MyApp2

They will be cloned beside the settings repo into C:\source, giving us the following structure:

  • C:\source\MyApp1
  • C:\source\MyApp2

R# settings files allow you to reference other settings files via a relative path. A repo-specific R# settings C:\source\MyApp1\MyApp1.sln.DotSettings might look like this:

<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=15C315CEAAF9FC4EA4785B81F2986594/AbsolutePath/@EntryValue">..\Codestyle\MyCompany.DotSettings</s:String>
    <s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=15C315CEAAF9FC4EA4785B81F2986594/RelativePath/@EntryValue">..\Codestyle\MyCompany.DotSettings</s:String>
    <s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=15C315CEAAF9FC4EA4785B81F2986594/@KeyIndexDefined">True</s:Boolean>
    <s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File15C315CEAAF9FC4EA4785B81F2986594/@KeyIndexDefined">True</s:Boolean>
    <s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File15C315CEAAF9FC4EA4785B81F2986594/RelativePriority/@EntryValue">1</s:Double>

As you can see, the repo-specific R# config C:\source\MyApp1\MyApp1.sln.DotSettings references the shared MyCompany.DotSettings from the other repo.

The only caveat is that you make certain assumptions and implicit requirements for the directory structure (e.g. renaming the cloned codestyle directory from C:\source\CodeStyle to C:\source\CodeStyleSettings locally) will break this approach. However, we preferred having a shared R# settings file; therefore, this compromise was okay for us.

Another approach would be to use a Git submodule - this frees you from the previously described problem of a directory structure that is implicitly set in stone.

You might wonder what the file CreateSymbolicLinkForEditorconfig.ps1 is about. Since .editorconfig allows directory-based inheritance (i.e C:\source\.editorconfig will automatically be applied to all directories in C:\source), we somehow needed to "move" the file C:\source\CodeStyle\.editorconfig one directory up to C:\source\.editorconfig so that all other repos can pick it up.
For the sake of simplicity, we create a symbolic link with the PowerShell script CreateSymbolicLinkForEditorconfig.ps1:

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    Write-Host "Running elevated..."
    $arguments = "& '" + $myinvocation.mycommand.definition + "'"
    Start-Process powershell -Verb runAs -ArgumentList $arguments
}

$sourceFile = "$PSScriptRoot\.editorconfig"
$destinationLink = "$PSScriptRoot\..\.editorconfig"

if (Test-Path -Path $destinationLink) {
    Write-Host "File '$destinationLink' already exists"
}
else {
    New-Item -ItemType SymbolicLink -Path $destinationLink -Value $sourceFile
    Write-Host "Created Symbolic Link '$destinationLink' pointing to '$sourceFile'"
}

Hope this helps!

2
  • Thank you for your answer! first of all it's nice i'm not the only one facing this problem. One big problem for me in this solution is that the developers will need to manually pull the CodeStyle repo whenever there are changes
    – Tal B
    Commented Jul 11 at 7:21
  • You could solve that to a certain degree with a Git submodule, I guess, by always pulling the submodule, too.
    – mu88
    Commented Jul 11 at 8:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.