[[Обновление .csproj файлов|Вернуться назад]]
### Как это устроено
- Плагин _JetBrains Rider Editor_ при старте создаёт файл
`Library/EditorInstance.json`, где пишет **PID** и **порт** TCP-сервера, через который IDE управляет Editor’ом. ([GitHub](https://github.com/JetBrains/resharper-unity "GitHub - JetBrains/resharper-unity: Unity support for both ReSharper and Rider"))
- По этому же порту Rider шлёт JSON-команды: _play_, _pause_, _refresh_, _openFile_ и т. д. ([JetBrains](https://www.jetbrains.com/help/rider/Unity.html?utm_source=chatgpt.com "Game development for Unity | JetBrains Rider"))
### Мини-клиент на C\#
```csharp
// NuGet: JetBrains.Rd, JetBrains.Rider.Model, Newtonsoft.Json
using System.IO;
using Newtonsoft.Json.Linq;
using JetBrains.Rd;
using JetBrains.Rd.Impl;
public static async Task RefreshUnityAsync(string projectPath)
{
// 1. Читаем Library/EditorInstance.json
var json = JObject.Parse(
File.ReadAllText(Path.Combine(projectPath, "Library", "EditorInstance.json")));
int port = json["Port"].Value<int>();
// 2. Открываем RD-протокол
var scheduler = new SingleThreadScheduler("unity-protocol");
var protocol = new Protocol("unityCaller", Serializers.FromAssemblies(AppDomain.CurrentDomain),
new SocketWire.Client(scheduler, new IPEndPoint(IPAddress.Loopback, port)),
scheduler);
// 3. Берём модель Unity и вызываем Refresh
var model = new UnityModel(protocol, "UnityModel");
model.Refresh.Start(); // эквивалент Ctrl+R в Rider
await model.Refresh.Result; // дождаться выполнения (по желанию)
}
```
_Команда `Refresh` заставляет Editor выполнить `AssetDatabase.Refresh()` и `SyncSolution()`_ — то, что требуется для пересоздания `.csproj`. ([docs.unity3d.com](https://docs.unity3d.com/ScriptReference/AssetDatabase.Refresh.html?utm_source=chatgpt.com "AssetDatabase.Refresh - Scripting API"))
> ⚠️ **Совместимость.** В разных версиях Rider имя модели/метода может меняться. При апдейте IDE проверяйте, что сборки JetBrains RD совпадают с плагином в Unity.
---