Skip to content

Commit

Permalink
Improve file-access behaviour for project.assets.json
Browse files Browse the repository at this point in the history
- Ensure file stream is closed as soon as the contents have been read
- Use FileShare.Read to enable simultaneous read-access by other processes

tintoy/msbuild-project-tools-vscode#139
  • Loading branch information
tintoy committed Nov 27, 2023
1 parent a01749a commit 68138dc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/LanguageServer.Common/Utilities/MSBuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ public static Dictionary<string, SemanticVersion> GetReferencedPackageVersions(t
JsonNode rootNode;
try
{
rootNode = JsonNode.Parse(projectAssetsFile.OpenRead());
using (FileStream projectAssetsContent = projectAssetsFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
{
rootNode = JsonNode.Parse(projectAssetsContent);
}
}
catch (Exception cannotLoadProjectAssetsJson)
{
Expand Down

0 comments on commit 68138dc

Please sign in to comment.