csharpdeeb25a2 | 1 | using System.Diagnostics.CodeAnalysis; |
| 2 | using CascadeIDE.Contracts; |
| 3 | using CascadeIDE.Models; |
| 4 | |
| 5 | namespace CascadeIDE.Features.Launch.Application; |
| 6 | |
| 7 | /// <summary>Путь к .csproj относительно корня каталога решения.</summary> |
| 8 | [ComputingUnit("paths-launch")] |
| 9 | public static class LaunchProjectRelativePath |
| 10 | { |
| 11 | public static bool TryGetRelativeToSolutionDirectory( |
| 12 | string solutionRootDirectory, |
| 13 | string csprojFullPath, |
| 14 | [NotNullWhen(true)] out string? relativePath, |
| 15 | [NotNullWhen(false)] out string? error) |
| 16 | { |
| 17 | relativePath = null; |
| 18 | error = null; |
| 19 | try |
| 20 | { |
| 21 | var rel = Path.GetRelativePath(solutionRootDirectory, CanonicalFilePath.Normalize(csprojFullPath)); |
| 22 | if (rel.StartsWith("..", StringComparison.Ordinal)) |
| 23 | { |
| 24 | error = "Проект должен быть внутри каталога решения."; |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | relativePath = rel; |
| 29 | return true; |
| 30 | } |
| 31 | catch (Exception ex) |
| 32 | { |
| 33 | error = ex.Message; |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
View only · write via MCP/CIDE