-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Add support for solution filter files (.slnf) and fix version detection in launcher #2676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
laske185
wants to merge
4
commits into
stride3d:master
Choose a base branch
from
laske185:feature/2675-solution-filter-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b86cda
feat: Add support for solution filter files (.slnf) and fix version d…
laske185 864343e
refactor: Replace Regex with SolutionFileRegex for solution file dete…
laske185 50a1159
fix: Include parent solution folders for projects in filtered solution
laske185 d53ecf0
fix: Update filtered solution path assignment and improve null check …
laske185 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
sources/core/Stride.Core.Design/VisualStudio/SolutionFilter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #region License | ||
|
|
||
| // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) | ||
| // This file is distributed under MIT License. See LICENSE.md for details. | ||
|
|
||
| #endregion | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Stride.Core.VisualStudio; | ||
|
|
||
| /// <summary> | ||
| /// Represents a Visual Studio solution filter file (.slnf). | ||
| /// </summary> | ||
| public class SolutionFilter | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SolutionFilter"/> class. | ||
| /// </summary> | ||
| public SolutionFilter() | ||
| { | ||
| SolutionPath = string.Empty; | ||
| ProjectPaths = []; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the path to the solution file referenced by this solution filter. | ||
| /// </summary> | ||
| public string SolutionPath { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the list of project paths included in the solution filter. | ||
| /// </summary> | ||
| public List<string> ProjectPaths { get; } = []; | ||
|
|
||
| /// <summary> | ||
| /// Loads a solution filter from a file path. | ||
| /// </summary> | ||
| /// <param name="solutionFilterPath">The full path to the solution filter file.</param> | ||
| /// <returns>A populated SolutionFilter instance.</returns> | ||
| public static SolutionFilter FromFile(string solutionFilterPath) | ||
| { | ||
| using var stream = new FileStream(solutionFilterPath, FileMode.Open, FileAccess.Read); | ||
| return FromStream(solutionFilterPath, stream); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Loads a solution filter from a stream. | ||
| /// </summary> | ||
| /// <param name="solutionFilterPath">The full path to the solution filter file.</param> | ||
| /// <param name="stream">The stream containing the solution filter data.</param> | ||
| /// <returns>A populated SolutionFilter instance.</returns> | ||
| public static SolutionFilter FromStream(string solutionFilterPath, Stream stream) | ||
| { | ||
| using var filterReader = new SolutionFilterReader(solutionFilterPath, stream); | ||
| return filterReader.ReadSolutionFilterFile(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// JSON model for deserializing solution filter files. | ||
| /// </summary> | ||
| internal class SolutionFilterData | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the solution information. | ||
| /// </summary> | ||
| [JsonPropertyName("solution")] | ||
Kryptos-FR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public SolutionInfo? Solution { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Represents solution information in a solution filter file. | ||
| /// </summary> | ||
| public class SolutionInfo | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the relative path to the solution file. | ||
| /// </summary> | ||
| [JsonPropertyName("path")] | ||
| public string? Path { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the list of project paths in the solution filter. | ||
| /// </summary> | ||
| [JsonPropertyName("projects")] | ||
| public List<string>? Projects { get; set; } | ||
| } | ||
| } | ||
109 changes: 109 additions & 0 deletions
109
sources/core/Stride.Core.Design/VisualStudio/SolutionFilterReader.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #region License | ||
|
|
||
| // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) | ||
| // This file is distributed under MIT License. See LICENSE.md for details. | ||
|
|
||
| #endregion | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Text.Json; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace Stride.Core.VisualStudio; | ||
|
|
||
| internal class SolutionFilterReader : IDisposable | ||
Kryptos-FR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private readonly string solutionFilterPath; | ||
| private readonly string solutionFilterDirectory; | ||
| private StreamReader? reader; | ||
Kryptos-FR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private bool disposed; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SolutionFilterReader"/> class. | ||
| /// </summary> | ||
| /// <param name="solutionFilterPath">The solution filter path.</param> | ||
| public SolutionFilterReader(string solutionFilterPath) | ||
| : this(solutionFilterPath, new FileStream(solutionFilterPath, FileMode.Open, FileAccess.Read)) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SolutionFilterReader"/> class. | ||
| /// </summary> | ||
| /// <param name="solutionFilterPath">The solution filter path.</param> | ||
| /// <param name="stream">The stream containing the solution filter data.</param> | ||
| public SolutionFilterReader(string solutionFilterPath, Stream stream) | ||
| { | ||
| this.solutionFilterPath = solutionFilterPath; | ||
| solutionFilterDirectory = Path.GetDirectoryName(solutionFilterPath) ?? string.Empty; | ||
| reader = new StreamReader(stream); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Reads the solution filter file and returns a SolutionFilter instance. | ||
| /// </summary> | ||
| /// <returns>A populated SolutionFilter instance.</returns> | ||
| public SolutionFilter ReadSolutionFilterFile() | ||
| { | ||
| #if NET7_0_OR_GREATER | ||
| ObjectDisposedException.ThrowIf(disposed, this); | ||
| #else | ||
| if (disposed) throw new ObjectDisposedException(nameof(SolutionFilterReader)); | ||
| #endif | ||
|
|
||
| var solutionFilter = new SolutionFilter(); | ||
|
|
||
| try | ||
| { | ||
| // Read and deserialize the JSON content | ||
| var jsonContent = reader!.ReadToEnd(); | ||
Kryptos-FR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var options = new JsonSerializerOptions | ||
| { | ||
| PropertyNameCaseInsensitive = true | ||
| }; | ||
|
|
||
| var filterData = JsonSerializer.Deserialize<SolutionFilterData>(jsonContent, options); | ||
|
|
||
| if (filterData?.Solution?.Path == null) | ||
Kryptos-FR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| throw new SolutionFileException($"Invalid solution filter file: {solutionFilterPath}. Missing or invalid 'solution.path' property."); | ||
| } | ||
|
|
||
| // Resolve the solution path relative to the solution filter | ||
| var relativeSolutionPath = filterData.Solution.Path.Replace('\\', Path.DirectorySeparatorChar); | ||
| solutionFilter.SolutionPath = Path.GetFullPath(Path.Combine(solutionFilterDirectory, relativeSolutionPath)); | ||
|
|
||
| // Process project paths | ||
| if (filterData.Solution.Projects != null) | ||
| { | ||
| foreach (var projectPath in filterData.Solution.Projects) | ||
| { | ||
| if (!string.IsNullOrEmpty(projectPath)) | ||
| { | ||
| solutionFilter.ProjectPaths.Add(projectPath.Replace('\\', Path.DirectorySeparatorChar)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch (JsonException ex) | ||
| { | ||
| throw new SolutionFileException($"Error parsing solution filter file: {solutionFilterPath}", ex); | ||
| } | ||
|
|
||
| return solutionFilter; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Disposes resources used by the reader. | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| disposed = true; | ||
| if (reader != null) | ||
| { | ||
| reader.Dispose(); | ||
| reader = null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a compile-time regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the regex to a static readonly field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more thinking of using the new
GeneratedRegexattribute that triggers a source generator.See
stride/sources/core/Stride.Core.Design/PackageVersion.cs
Lines 26 to 32 in 665a05e
stride/sources/core/Stride.Core.Design/PackageVersion.cs
Lines 357 to 362 in 665a05e